This commit is contained in:
mimie 2025-05-06 16:32:53 +02:00
commit 9f2106ba2d
2 changed files with 49 additions and 5 deletions

View File

@ -207,13 +207,49 @@ public class Board {
/* saving-loading feature :*/
public String[] toFileRep() {
//TODO
return null;
}
String[] saveFile = new String[8]; // creation of the string array which will be the one returned
String actualBoard = this.toString();
int nbLine = 0;
saveFile[0] = "";
for(int i = 0; i<200 ;i++) { // there are in total 200 strings in the
if (actualBoard.charAt(i) == '\n') {
nbLine+=1;
if (nbLine < 8 ) {
saveFile[nbLine]= "";
}
}
else {
saveFile[nbLine] += actualBoard.charAt(i);
}
}
return saveFile;
}
public Board(String[] array) {
//TODO
this.colNum = 8;
this.lineNum = 8;
x = -1;
y = -1;
turnNumber= 0;
pieces = new ArrayList<>();
for(int i=0; i<8;i++) { // this will be the Y coordinate
for(int j=0; j<8;j++) { // this will be the X coordinate
if(array[i].charAt(j*3) != ' ') {
Piece newPiece = new Piece(true,PieceType.Pawn,0,0);
if(array[i].charAt(j*3)=='B') {
newPiece.setIsWhite(false);
}
else {
newPiece.setIsWhite(true);
}
newPiece.setType(PieceType.fromSummary(array[i].charAt((j*3)+1)));
newPiece.setX(j);
newPiece.setY(i);
pieces.add(newPiece);
}
}
}
}
/* The following methods require more work ! */

View File

@ -28,6 +28,14 @@ public class Piece {
this.y = y;
}
public void setIsWhite(boolean isWhite) {
this.isWhite = isWhite;
}
public void setType(PieceType type) {
this.type = type;
}
public PieceType getType() {
return type;
}