37 lines
772 B
Java
37 lines
772 B
Java
package chess.controller.commands;
|
|
|
|
import chess.controller.Command;
|
|
import chess.controller.event.GameListener;
|
|
import chess.model.Coordinate;
|
|
import chess.model.Game;
|
|
import chess.model.Piece;
|
|
|
|
/**
|
|
* Command to check the possible moves for a given piece.
|
|
*/
|
|
public class GetPieceAtCommand extends Command{
|
|
|
|
private final Coordinate pieceCoords;
|
|
private Piece piece;
|
|
|
|
public GetPieceAtCommand(Coordinate pieceCoords) {
|
|
this.pieceCoords = pieceCoords;
|
|
this.piece = null;
|
|
}
|
|
|
|
@Override
|
|
public CommandResult execute(Game game, GameListener outputSystem) {
|
|
if (!pieceCoords.isValid())
|
|
return CommandResult.NotAllowed;
|
|
|
|
this.piece = game.getBoard().pieceAt(pieceCoords);
|
|
|
|
return CommandResult.NotMoved;
|
|
}
|
|
|
|
public Piece getPiece() {
|
|
return piece;
|
|
}
|
|
|
|
}
|