iaaaaaaaaaaaaaa
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package chess.controller.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
import chess.model.Piece;
|
||||
|
||||
public class GetAllowedMovesPieceCommand extends Command {
|
||||
|
||||
private final Coordinate start;
|
||||
private List<Coordinate> destinations;
|
||||
|
||||
public GetAllowedMovesPieceCommand(Coordinate start) {
|
||||
this.start = start;
|
||||
this.destinations = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
Piece piece = board.pieceAt(start);
|
||||
|
||||
if (piece == null)
|
||||
return CommandResult.NotAllowed;
|
||||
|
||||
if (piece.getColor() != game.getPlayerTurn())
|
||||
return CommandResult.NotAllowed;
|
||||
|
||||
this.destinations = board.getAllowedMoves(start);
|
||||
return CommandResult.NotMoved;
|
||||
}
|
||||
|
||||
public List<Coordinate> getDestinations() {
|
||||
return destinations;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user