add CommanderSender (Fixes #9)
All checks were successful
Linux arm64 / Build (push) Successful in 36s
All checks were successful
Linux arm64 / Build (push) Successful in 36s
This commit is contained in:
102
app/src/main/java/chess/controller/CommandSender.java
Normal file
102
app/src/main/java/chess/controller/CommandSender.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package chess.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import chess.controller.Command.CommandResult;
|
||||
import chess.controller.commands.CastlingCommand;
|
||||
import chess.controller.commands.GetAllowedCastlingsCommand;
|
||||
import chess.controller.commands.GetAllowedMovesPieceCommand;
|
||||
import chess.controller.commands.GetPieceAtCommand;
|
||||
import chess.controller.commands.GetPlayerMovesCommand;
|
||||
import chess.controller.commands.MoveCommand;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.controller.commands.PromoteCommand;
|
||||
import chess.controller.commands.SurrenderCommand;
|
||||
import chess.controller.commands.UndoCommand;
|
||||
import chess.controller.commands.GetAllowedCastlingsCommand.CastlingResult;
|
||||
import chess.controller.commands.PromoteCommand.PromoteType;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Move;
|
||||
import chess.model.Piece;
|
||||
|
||||
public interface CommandSender {
|
||||
|
||||
CommandExecutor getCommandExecutor();
|
||||
|
||||
default CommandResult sendCommand(Command cmd, CommandExecutor commandExecutor) {
|
||||
CommandResult result = commandExecutor.executeCommand(cmd);
|
||||
if (result == CommandResult.NotAllowed) {
|
||||
// maybe do something
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
default CommandResult sendCommand(Command cmd) {
|
||||
return sendCommand(cmd, getCommandExecutor());
|
||||
}
|
||||
|
||||
// inputs
|
||||
|
||||
default CastlingResult getAllowedCastlings() {
|
||||
GetAllowedCastlingsCommand cmd = new GetAllowedCastlingsCommand();
|
||||
sendCommand(cmd);
|
||||
return cmd.getCastlingResult();
|
||||
}
|
||||
|
||||
default Piece getPieceAt(int x, int y) {
|
||||
return getPieceAt(new Coordinate(x, y));
|
||||
}
|
||||
|
||||
default Piece getPieceAt(Coordinate coordinate) {
|
||||
GetPieceAtCommand cmd = new GetPieceAtCommand(coordinate);
|
||||
sendCommand(cmd);
|
||||
return cmd.getPiece();
|
||||
}
|
||||
|
||||
default boolean isCellEmpty(int x, int y) {
|
||||
return getPieceAt(x, y) == null;
|
||||
}
|
||||
|
||||
default List<Move> getPlayerMoves() {
|
||||
GetPlayerMovesCommand cmd = new GetPlayerMovesCommand();
|
||||
sendCommand(cmd);
|
||||
return cmd.getMoves();
|
||||
}
|
||||
|
||||
default List<Coordinate> getPieceAllowedMoves(Coordinate piecePos) {
|
||||
GetAllowedMovesPieceCommand cmd = new GetAllowedMovesPieceCommand(piecePos);
|
||||
sendCommand(cmd);
|
||||
return cmd.getDestinations();
|
||||
}
|
||||
|
||||
// outputs
|
||||
|
||||
default CommandResult sendCastling() {
|
||||
return sendCommand(new CastlingCommand(false));
|
||||
}
|
||||
|
||||
default CommandResult sendBigCastling() {
|
||||
return sendCommand(new CastlingCommand(false));
|
||||
}
|
||||
|
||||
default CommandResult sendMove(Move move) {
|
||||
return sendCommand(new MoveCommand(move));
|
||||
}
|
||||
|
||||
default CommandResult sendStartGame() {
|
||||
return sendCommand(new NewGameCommand());
|
||||
}
|
||||
|
||||
default CommandResult sendPawnPromotion(PromoteType promote) {
|
||||
return sendCommand(new PromoteCommand(promote));
|
||||
}
|
||||
|
||||
default CommandResult sendSurrender(Color player) {
|
||||
return sendCommand(new SurrenderCommand(player));
|
||||
}
|
||||
|
||||
default CommandResult sendUndo() {
|
||||
return sendCommand(new UndoCommand());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user