feat: add undo
This commit is contained in:
@@ -16,7 +16,7 @@ public class CastlingCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult undo(Game game, OutputSystem outputSystem) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'undo'");
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class GrandCastlingCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult undo(Game game, OutputSystem outputSystem) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'undo'");
|
||||
}
|
||||
|
||||
@@ -57,10 +57,11 @@ public class MoveCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult undo(Game game, OutputSystem outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
board.undoMove(move, deadPiece);
|
||||
return CommandResult.Moved;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -75,7 +75,7 @@ public class PromoteCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult undo(Game game, OutputSystem outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
Piece promoted = board.pieceAt(this.pieceCoords);
|
||||
@@ -84,6 +84,8 @@ public class PromoteCommand extends PlayerCommand {
|
||||
|
||||
Color player = promoted.getColor();
|
||||
board.pieceComes(new Pawn(player), this.pieceCoords);
|
||||
|
||||
return CommandResult.ActionNeeded;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,14 +2,18 @@ package chess.controller.commands;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.model.Game;
|
||||
|
||||
public class UndoCommand extends Command{
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
//TODO
|
||||
return CommandResult.Moved;
|
||||
PlayerCommand lastAction = game.getLastAction();
|
||||
if (lastAction == null)
|
||||
return CommandResult.NotAllowed;
|
||||
|
||||
return lastAction.undo(game, outputSystem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user