add castling commands
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user