This commit is contained in:
MSI-AB\antoineB 2025-04-18 17:29:46 +02:00
parent 440a02ecd4
commit d06059cf44
1 changed files with 28 additions and 2 deletions

View File

@ -83,10 +83,36 @@ public class Board {
pieces.clear(); pieces.clear();
} }
@Override
public String toString() { public String toString() {
//TODO String[][] grid = new String[height][width];
return "";
// Fill the grid with empty squares
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
grid[y][x] = "--";
} }
}
// Place pieces on the grid
for (Piece piece : pieces) {
String color = piece.isWhite() ? "W" : "B";
String type = piece.getType().toString().substring(0, 1); // e.g., "P" for Pawn
grid[piece.getY()][piece.getX()] = color + type;
}
// Build the string row by row
StringBuilder sb = new StringBuilder();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
sb.append(grid[y][x]).append(" ");
}
sb.append("\n");
}
return sb.toString();
}
public ArrayList<Piece> getPieces() { public ArrayList<Piece> getPieces() {
return pieces; // this refers to the instance variable return pieces; // this refers to the instance variable