promote not that uggly

This commit is contained in:
2025-04-02 17:19:26 +02:00
parent 97cafb903a
commit 9179b3cda9
7 changed files with 142 additions and 27 deletions

View File

@@ -3,8 +3,8 @@ package chess.io.commands;
import chess.io.Command;
import chess.io.CommandResult;
import chess.io.OutputSystem;
import chess.io.commands.PromoteCommand.PromoteType;
import chess.model.ChessBoard;
import chess.model.Color;
import chess.model.Game;
import chess.model.Move;
import chess.model.Piece;
@@ -17,6 +17,10 @@ public class MoveCommand extends Command {
this.move = move;
}
public Move getMove() {
return move;
}
@Override
public CommandResult execute(Game game, OutputSystem outputSystem) {
final ChessBoard board = game.getBoard();
@@ -39,25 +43,7 @@ public class MoveCommand extends Command {
return CommandResult.NotAllowed;
}
checkGameStatus(game, outputSystem);
return CommandResult.Moved;
}
private void checkGameStatus(Game game, OutputSystem outputSystem) {
final ChessBoard board = game.getBoard();
final Color enemy = Color.getEnemy(game.getPlayerTurn());
if (board.isKingInCheck(enemy)) {
if (board.hasAllowedMoves(enemy)) {
outputSystem.kingIsInCheck();
} else {
outputSystem.kingIsInMat();
outputSystem.winnerIs(game.getPlayerTurn());
}
} else if(!board.hasAllowedMoves(enemy)) {
outputSystem.patSituation();
}
}
}