still buggy but now state comes back to normal at turn 0
This commit is contained in:
parent
dada9a54cf
commit
48a3f7468d
|
|
@ -86,7 +86,7 @@ public class Board {
|
|||
pieces.add(new Piece(i, 6, PieceType.Pawn, true));
|
||||
}
|
||||
|
||||
saveBoardState(); // to save first state of the board
|
||||
|
||||
}
|
||||
|
||||
public void cleanBoard() {
|
||||
|
|
@ -269,14 +269,21 @@ public class Board {
|
|||
}
|
||||
|
||||
public void undoLastMove() {
|
||||
if (turnNb > 0) { // only if turnnb is positive
|
||||
turnNb--; // decrease turnNb
|
||||
ArrayList<Piece> previousState = boardHistory.get(turnNb);// create a temporary arraylist
|
||||
if (turnNb > 1) { // only if turnnb is positive
|
||||
|
||||
ArrayList<Piece> previousState = boardHistory.get(turnNb - 1);// create a temporary arraylist
|
||||
|
||||
pieces.clear(); // removes all pieces from arraylist of pieces used
|
||||
pieces.addAll(previousState); // add all pieces from previous state of board to arraylist
|
||||
boardHistory.remove(turnNb + 1); // removes the last state of board from memory
|
||||
}
|
||||
boardHistory.remove(turnNb);
|
||||
turnNb--;
|
||||
|
||||
}else if (turnNb == 1) {
|
||||
turnNb--;
|
||||
pieces.clear();
|
||||
boardHistory.clear();
|
||||
populateBoard();
|
||||
}
|
||||
}
|
||||
|
||||
public Board(Board board) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue