end lab
This commit is contained in:
parent
440a02ecd4
commit
d06059cf44
|
|
@ -83,10 +83,36 @@ public class Board {
|
|||
pieces.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
//TODO
|
||||
return "";
|
||||
String[][] grid = new String[height][width];
|
||||
|
||||
// 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() {
|
||||
return pieces; // this refers to the instance variable
|
||||
|
|
|
|||
Loading…
Reference in New Issue