From 4815212520e1083245e81464f8a410ed411bc843 Mon Sep 17 00:00:00 2001 From: lrave Date: Thu, 22 May 2025 18:05:24 +0200 Subject: [PATCH] commenting board --- src/backend/Board.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index 1967c86..782f094 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -109,20 +109,20 @@ public class Board { } } - public String toString() { - StringBuilder str = new StringBuilder(); + 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(); - if (!piece.isWhite()) { - pieceSymbol = pieceSymbol.toLowerCase(); + String pieceSymbol = piece.getType().getSummary(); // Pieces replaced by their symbols (all caps for now) + if (!piece.isWhite()) { + 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 getPieces() { + public ArrayList getPieces() { // lists all pieces present on the board. ArrayList 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;