saved and upload
This commit is contained in:
parent
78c2c134bc
commit
6b3ee1b1b2
|
|
@ -182,13 +182,38 @@ public class Board {
|
|||
/* saving-loading feature :*/
|
||||
|
||||
public String[] toFileRep() {
|
||||
//TODO
|
||||
return null;
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
|
||||
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) {
|
||||
//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 ! */
|
||||
|
|
|
|||
Loading…
Reference in New Issue