better undo
This commit is contained in:
@@ -10,10 +10,13 @@ import chess.model.Piece;
|
||||
import chess.model.visitor.PiecePathChecker;
|
||||
|
||||
public class MoveCommand extends PlayerCommand {
|
||||
|
||||
private final Move move;
|
||||
private Piece deadPiece;
|
||||
|
||||
public MoveCommand(Move move) {
|
||||
this.move = move;
|
||||
this.deadPiece = null;
|
||||
}
|
||||
|
||||
public Move getMove() {
|
||||
@@ -39,6 +42,7 @@ public class MoveCommand extends PlayerCommand {
|
||||
if (!valid)
|
||||
return CommandResult.NotAllowed;
|
||||
|
||||
this.deadPiece = board.pieceAt(move.getFinish());
|
||||
board.applyMove(move);
|
||||
|
||||
if (board.isKingInCheck(game.getPlayerTurn())) {
|
||||
@@ -51,7 +55,9 @@ public class MoveCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public void undo(Game game, OutputSystem outputSystem) {
|
||||
game.getBoard().undoLastMove();
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
board.undoMove(move, deadPiece);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user