undo
This commit is contained in:
parent
9331910221
commit
a6dab9e366
|
|
@ -352,7 +352,26 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void undoLastMove() {
|
public void undoLastMove() {
|
||||||
|
if (moveHistory.isEmpty()) return;
|
||||||
|
|
||||||
|
Move lastMove = moveHistory.remove(moveHistory.size() - 1);
|
||||||
|
Piece movedPiece = lastMove.getPieceMoved();
|
||||||
|
|
||||||
|
// Move the piece back to its original position
|
||||||
|
movedPiece.setPosition(lastMove.getFromX(), lastMove.getFromY());
|
||||||
|
|
||||||
|
// Restore the captured piece if any
|
||||||
|
if (lastMove.getPieceCaptured() != null) {
|
||||||
|
pieces.add(lastMove.getPieceCaptured());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch turn and decrease turn count
|
||||||
|
turnWhite = !turnWhite;
|
||||||
|
turnNumber--;
|
||||||
|
|
||||||
|
// Clear selection and highlights
|
||||||
|
selected = null;
|
||||||
|
highlighted.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue