add CommandResult.NeedsAction

This commit is contained in:
2025-04-04 20:55:46 +02:00
parent 416cfadc9b
commit 7b07423175
5 changed files with 43 additions and 20 deletions

View File

@@ -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;
}
}