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.");
|
||||
return;
|
||||
}
|
||||
// store the current state before making a move
|
||||
getLastMove();
|
||||
|
||||
//store for castling
|
||||
int originalX = selectedPiece.getX();
|
||||
|
|
@ -316,11 +318,10 @@ public class Board {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void getLastMove (int x, int y) {// it saves the current state before making a move
|
||||
|
||||
previousStates.add(new Board(this)); // Use the existing constructor to create a copy
|
||||
getLastMove(selectedX, selectedY);
|
||||
}
|
||||
//new method to save the current state of the board
|
||||
public void getLastMove() {
|
||||
previousStates.add(new Board(this)); // Create a copy of the current board state
|
||||
}
|
||||
|
||||
public void undoLastMove() {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue