let's goo

This commit is contained in:
chloe 2025-05-13 13:48:26 +02:00
parent 22e014acee
commit 4cb0476e51
1 changed files with 54 additions and 8 deletions

View File

@ -141,7 +141,7 @@ public class Board {
} }
} else { } else {
if (selectedX == x && selectedY == y) { if (selectedX == x && selectedY == y) {
// Unselect
hasSelectedPiece = false; hasSelectedPiece = false;
} else { } else {
Piece selectedPiece = board[selectedX][selectedY]; Piece selectedPiece = board[selectedX][selectedY];
@ -165,7 +165,6 @@ public class Board {
turnWhite = !turnWhite; turnWhite = !turnWhite;
turnNumber++; turnNumber++;
// Unselect
hasSelectedPiece = false; hasSelectedPiece = false;
} }
} }
@ -178,18 +177,65 @@ public class Board {
/* saving-loading feature */ /* saving-loading feature */
public String[] toFileRep() { public String[] toFileRep() {
return null; ArrayList<String> fileLines = new ArrayList<>();
} fileLines.add(turnNumber + "," + (turnWhite ? "white" : "black"));
fileLines.add(width + "," + height);
ArrayList<Piece> pieces = getPieces();
for (Piece piece : pieces) {
StringBuilder pieceInfo = new StringBuilder();
pieceInfo.append(piece.getType()).append(",");
pieceInfo.append(piece.getX()).append(",");
pieceInfo.append(piece.getY()).append(",");
pieceInfo.append(piece.isWhite() ? "W" : "B");
fileLines.add(pieceInfo.toString());
}
return fileLines.toArray(new String[0]);
}
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[] dimensions = array[1].split(",");
width = Integer.parseInt(dimensions[0]);
height = Integer.parseInt(dimensions[1]);
board = new Piece[width][height];
for (int i = 2; i < array.length; i++) {
String[] pieceInfo = array[i].split(",");
PieceType pieceType = PieceType.valueOf(pieceInfo[0]);
int x = Integer.parseInt(pieceInfo[1]);
int y = Integer.parseInt(pieceInfo[2]);
boolean isWhite = pieceInfo[3].equals("W");
board[x][y] = new Piece(x, y, isWhite, pieceType);
}
hasSelectedPiece = false;
selectedX = -1;
selectedY = -1;
} }
private ArrayList<int[]> highlightedSquares = new ArrayList<>();
/* 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) {
return false; for (int[] pos : highlightedSquares) {
} if (pos[0] == x && pos[1] == y) {
return true;
}
}
return false;
}
public void undoLastMove() { public void undoLastMove() {
// TODO // TODO
} }