add CommandResult.NeedsAction
This commit is contained in:
@@ -3,6 +3,7 @@ package chess.io.commands;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.io.PlayerCommand;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
import chess.model.Move;
|
||||
import chess.model.Piece;
|
||||
@@ -49,6 +50,9 @@ public class MoveCommand extends PlayerCommand {
|
||||
return CommandResult.NotAllowed;
|
||||
}
|
||||
|
||||
if (shouldPromote(game, outputSystem))
|
||||
return CommandResult.ActionNeeded;
|
||||
|
||||
return CommandResult.Moved;
|
||||
}
|
||||
|
||||
@@ -59,4 +63,14 @@ public class MoveCommand extends PlayerCommand {
|
||||
board.undoMove(move, deadPiece);
|
||||
}
|
||||
|
||||
private boolean shouldPromote(Game game, OutputSystem outputSystem) {
|
||||
Coordinate pawnPos = game.pawnPromotePosition();
|
||||
|
||||
if (pawnPos == null)
|
||||
return false;
|
||||
|
||||
outputSystem.promotePawn(pawnPos);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user