add castling + fix promote undo
This commit is contained in:
@@ -9,7 +9,6 @@ import chess.model.Game;
|
||||
import chess.model.Piece;
|
||||
import chess.model.pieces.Bishop;
|
||||
import chess.model.pieces.Knight;
|
||||
import chess.model.pieces.Pawn;
|
||||
import chess.model.pieces.Queen;
|
||||
import chess.model.pieces.Rook;
|
||||
import chess.model.visitor.PawnIdentifier;
|
||||
@@ -25,9 +24,12 @@ public class PromoteCommand extends PlayerCommand {
|
||||
|
||||
private final PromoteType promoteType;
|
||||
private Coordinate pieceCoords;
|
||||
private Piece oldPawn;
|
||||
|
||||
public PromoteCommand(PromoteType promoteType) {
|
||||
this.promoteType = promoteType;
|
||||
this.pieceCoords = null;
|
||||
this.oldPawn = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,6 +52,7 @@ public class PromoteCommand extends PlayerCommand {
|
||||
if (destY != enemyLine)
|
||||
return CommandResult.NotAllowed;
|
||||
|
||||
this.oldPawn = pawn;
|
||||
board.pieceComes(createPiece(this.promoteType, pawn.getColor()), this.pieceCoords);
|
||||
|
||||
return CommandResult.Moved;
|
||||
@@ -82,10 +85,11 @@ public class PromoteCommand extends PlayerCommand {
|
||||
|
||||
assert promoted != null;
|
||||
|
||||
Color player = promoted.getColor();
|
||||
board.pieceComes(new Pawn(player), this.pieceCoords);
|
||||
board.pieceComes(this.oldPawn, this.pieceCoords);
|
||||
|
||||
return CommandResult.ActionNeeded;
|
||||
game.getLastAction().undo(game, outputSystem);
|
||||
|
||||
return CommandResult.Moved;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user