player command
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package chess.io.commands;
|
||||
|
||||
import chess.io.Command;
|
||||
import chess.io.CommandResult;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.io.PlayerCommand;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
@@ -14,7 +14,7 @@ import chess.model.pieces.Pawn;
|
||||
import chess.model.pieces.Queen;
|
||||
import chess.model.pieces.Rook;
|
||||
|
||||
public class PromoteCommand extends Command {
|
||||
public class PromoteCommand extends PlayerCommand {
|
||||
|
||||
public enum PromoteType {
|
||||
Queen,
|
||||
@@ -71,4 +71,17 @@ public class PromoteCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(Game game, OutputSystem outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
Piece promoted = board.pieceAt(this.pieceCoords);
|
||||
|
||||
assert promoted != null;
|
||||
|
||||
Color player = promoted.getColor();
|
||||
board.pieceLeaves(this.pieceCoords);
|
||||
board.pieceComes(new Pawn(player), this.pieceCoords);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user