feat: add undo

This commit is contained in:
2025-04-05 10:53:41 +02:00
parent 8c2c6946d7
commit 2ec7be27ca
9 changed files with 71 additions and 11 deletions

View File

@@ -1,10 +1,15 @@
package chess.model;
import java.util.EmptyStackException;
import java.util.Stack;
import chess.controller.PlayerCommand;
import chess.model.visitor.PawnIdentifier;
public class Game {
private final ChessBoard board;
private Color playerTurn;
private final Stack<PlayerCommand> movesHistory;
public enum GameStatus {
Check, CheckMate, OnGoing, Pat;
@@ -12,6 +17,7 @@ public class Game {
public Game(ChessBoard board) {
this.board = board;
this.movesHistory = new Stack<>();
}
public ChessBoard getBoard() {
@@ -80,4 +86,17 @@ public class Game {
return null;
}
public void addAction(PlayerCommand command) {
this.movesHistory.add(command);
}
public PlayerCommand getLastAction() {
try {
PlayerCommand last = this.movesHistory.pop();
return last;
} catch (EmptyStackException e) {
return null;
}
}
}