feat: add undo
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user