saved and upload

This commit is contained in:
romca 2025-05-06 16:22:07 +02:00
parent 78c2c134bc
commit 6b3ee1b1b2
1 changed files with 28 additions and 3 deletions

View File

@ -182,13 +182,38 @@ public class Board {
/* saving-loading feature :*/ /* saving-loading feature :*/
public String[] toFileRep() { public String[] toFileRep() {
//TODO ArrayList<String> lines = new ArrayList<>();
return null;
lines.add(width + " " + height + " " + turnNumber + " " + isWhiteTurn);
for (Piece p : pieces) {
lines.add(p.getX() + " " + p.getY() + " " + p.getType().name() + " " + p.isWhite());
}
return lines.toArray(new String[0]);
} }
public Board(String[] array) { public Board(String[] array) {
//TODO String[] firstLine = array[0].split(" ");
this.width = Integer.parseInt(firstLine[0]);
this.height = Integer.parseInt(firstLine[1]);
this.turnNumber = Integer.parseInt(firstLine[2]);
this.isWhiteTurn = Boolean.parseBoolean(firstLine[3]);
this.pieces = new ArrayList<>();
// Remaining lines: x y PieceType isWhite
for (int i = 1; i < array.length; i++) {
String[] line = array[i].split(" ");
int x = Integer.parseInt(line[0]);
int y = Integer.parseInt(line[1]);
PieceType type = PieceType.valueOf(line[2]);
boolean isWhite = Boolean.parseBoolean(line[3]);
pieces.add(new Piece(x, y, type, isWhite));
}
// Optionally reset selection
selectedX = null;
selectedY = null;
} }
/* The following methods require more work ! */ /* The following methods require more work ! */