add castling commands

This commit is contained in:
2025-04-14 10:34:54 +02:00
parent 2578e8cf6f
commit 07016be5d8
3 changed files with 62 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
package chess.controller.commands;
import chess.controller.Command;
import chess.controller.event.GameListener;
import chess.model.Game;
public class GetAllowedCastlingsCommand extends Command{
public enum CastlingResult {
None, Small, Big, Both;
}
private CastlingResult castlingResult;
public GetAllowedCastlingsCommand() {}
@Override
public CommandResult execute(Game game, GameListener outputSystem) {
boolean canSmallCastle = game.getBoard().canSmallCastle(game.getPlayerTurn());
boolean canBigCastle = game.getBoard().canBigCastle(game.getPlayerTurn());
int result = 0;
if (canSmallCastle)
result += 1;
if (canBigCastle)
result += 2;
this.castlingResult = CastlingResult.values()[result];
return CommandResult.NotMoved;
}
public CastlingResult getCastlingResult() {
return castlingResult;
}
}