sauvegarde
This commit is contained in:
parent
865287dc3d
commit
9fd67df3c8
|
|
@ -164,15 +164,50 @@ public class Board {
|
||||||
/* saving-loading feature :*/
|
/* saving-loading feature :*/
|
||||||
|
|
||||||
public String[] toFileRep() {
|
public String[] toFileRep() {
|
||||||
//TODO
|
String[] lines = new String[height + 1];
|
||||||
return null;
|
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
StringBuilder row = new StringBuilder();
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
Piece p = getPieceAt(x, y);
|
||||||
|
if (p != null) {
|
||||||
|
row.append(p.isWhite() ? "W" : "B").append(p.getType().getSummary());
|
||||||
|
}
|
||||||
|
row.append(x < width - 1 ? "," : "");
|
||||||
|
}
|
||||||
|
lines[y] = row.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dernière ligne : couleur du joueur actif
|
||||||
|
lines[height] = isTurnWhite() ? "W" : "B";
|
||||||
|
|
||||||
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Board(String[] array) {
|
public Board(String[] array) {
|
||||||
//TODO
|
this.width = 8;
|
||||||
|
this.height = 8;
|
||||||
|
this.pieces = new ArrayList<>();
|
||||||
|
this.highlightedSquares = new ArrayList<>();
|
||||||
|
this.selectedX = -1;
|
||||||
|
this.selectedY = -1;
|
||||||
|
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
String[] cells = array[y].split(",", -1);
|
||||||
|
for (int x = 0; x < cells.length; x++) {
|
||||||
|
String cell = cells[x];
|
||||||
|
if (cell.length() == 2) {
|
||||||
|
boolean isWhite = cell.charAt(0) == 'W';
|
||||||
|
PieceType type = PieceType.fromSummary(cell.charAt(1));
|
||||||
|
setPiece(isWhite, type, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ligne 9 : couleur du joueur actif
|
||||||
|
this.turnNumber = array[height].equals("W") ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue