the board is populated with with the content described in the text file

This commit is contained in:
chloe 2025-05-13 16:55:51 +02:00
parent cfad9cd39e
commit 57a31421fe
1 changed files with 24 additions and 2 deletions

View File

@ -219,8 +219,30 @@ public class Board {
public Board(String[] array) { public Board(String[] array) {
// TODO String[] gameState = array[0].split(",");
turnNumber = Integer.parseInt(gameState[0]);
turnWhite = gameState[1].equals("white");
String[] dims = array[1].split(",");
width = Integer.parseInt(dims[0]);
height = Integer.parseInt(dims[1]);
board = new Piece[width][height];
for (int i = 2; i < array.length; i++) {
String[] p = array[i].split(",");
PieceType type = PieceType.valueOf(p[0]);
int x = Integer.parseInt(p[1]);
int y = Integer.parseInt(p[2]);
boolean isWhite = p[3].equals("W");
board[x][y] = new Piece(x, y, isWhite, type);
}
hasSelectedPiece = false;
selectedX = selectedY = -1;
highlightedSquares.clear();
} }
/* The following methods require more work */ /* The following methods require more work */
public boolean isHighlighted(int x, int y) { public boolean isHighlighted(int x, int y) {
@ -237,7 +259,7 @@ public class Board {
} }
public Board(Board board) { public Board(Board board) {
// TODO helloyo // TODO
} }
public void playMove(Move move) { public void playMove(Move move) {