Merge branch 'master' of https://gitarero.ecam.fr/aurele.wittke/OOP_Groupe_1A5_Project.git
This commit is contained in:
commit
9f2106ba2d
|
|
@ -207,13 +207,49 @@ public class Board {
|
||||||
/* saving-loading feature :*/
|
/* saving-loading feature :*/
|
||||||
|
|
||||||
public String[] toFileRep() {
|
public String[] toFileRep() {
|
||||||
//TODO
|
String[] saveFile = new String[8]; // creation of the string array which will be the one returned
|
||||||
return null;
|
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) {
|
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 ! */
|
/* The following methods require more work ! */
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,14 @@ public class Piece {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIsWhite(boolean isWhite) {
|
||||||
|
this.isWhite = isWhite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(PieceType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
public PieceType getType() {
|
public PieceType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue