commenting board
This commit is contained in:
parent
de01655fbb
commit
4815212520
|
|
@ -109,20 +109,20 @@ public class Board {
|
|||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
public String toString() { // Console window print
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append(" A B C D E F G H\n"); // columns letter at the top
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int y = 0; y < height; y++) { // treats the whole board and place letters corresponding to each piece type
|
||||
str.append(8 - y).append(" ");
|
||||
for (int x = 0; x < width; x++) {
|
||||
if (board[x][y] == null) {
|
||||
str.append("- ");
|
||||
str.append("- "); // null spaces replaced by -
|
||||
} else {
|
||||
Piece piece = board[x][y];
|
||||
String pieceSymbol = piece.getType().getSummary();
|
||||
String pieceSymbol = piece.getType().getSummary(); // Pieces replaced by their symbols (all caps for now)
|
||||
if (!piece.isWhite()) {
|
||||
pieceSymbol = pieceSymbol.toLowerCase();
|
||||
pieceSymbol = pieceSymbol.toLowerCase(); // Black pieces are replaced by their lowercase counterparts.
|
||||
}
|
||||
str.append(pieceSymbol).append(" ");
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ public class Board {
|
|||
return str.toString();
|
||||
}
|
||||
|
||||
public ArrayList<Piece> getPieces() {
|
||||
public ArrayList<Piece> getPieces() { // lists all pieces present on the board.
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
|
@ -148,14 +148,14 @@ public class Board {
|
|||
return pieces;
|
||||
}
|
||||
|
||||
public void userTouch(int x, int y) {
|
||||
if (selectedX == -1 && selectedY == -1) {
|
||||
public void userTouch(int x, int y) { //used to operate user touch
|
||||
if (selectedX == -1 && selectedY == -1) { // Initiate with impossible values for first turn
|
||||
if (board[x][y] != null && board[x][y].isWhite() == isTurnWhite()) {
|
||||
selectedX = x;
|
||||
selectedY = y;
|
||||
highlightedPositions = getValidMoves(board[x][y]);
|
||||
}
|
||||
} else {
|
||||
} else { // any other turn
|
||||
if (x == selectedX && y == selectedY) {
|
||||
selectedX = -1;
|
||||
selectedY = -1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue