Undo last move works !!!!!implementation of the method getLastMove in
userTouch + method modified to save the current state
This commit is contained in:
parent
3a6a8f2d72
commit
2a24efa355
|
|
@ -187,6 +187,8 @@ public class Board {
|
||||||
System.out.println("Invalid move — not in highlighted squares.");
|
System.out.println("Invalid move — not in highlighted squares.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// store the current state before making a move
|
||||||
|
getLastMove();
|
||||||
|
|
||||||
//store for castling
|
//store for castling
|
||||||
int originalX = selectedPiece.getX();
|
int originalX = selectedPiece.getX();
|
||||||
|
|
@ -316,11 +318,10 @@ public class Board {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getLastMove (int x, int y) {// it saves the current state before making a move
|
//new method to save the current state of the board
|
||||||
|
public void getLastMove() {
|
||||||
previousStates.add(new Board(this)); // Use the existing constructor to create a copy
|
previousStates.add(new Board(this)); // Create a copy of the current board state
|
||||||
getLastMove(selectedX, selectedY);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void undoLastMove() {
|
public void undoLastMove() {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue