diff --git a/src/backend/Board.java b/src/backend/Board.java index 68bb63a..5687e9f 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -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 ! */ diff --git a/src/backend/Piece.java b/src/backend/Piece.java index 81e4e93..dc6cc6e 100644 --- a/src/backend/Piece.java +++ b/src/backend/Piece.java @@ -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; }