Files
3DChess/app/src/main/java/chess/controller/commands/GetAllowedMovesPieceCommand.java
2025-04-12 11:12:36 +02:00

42 lines
1005 B
Java

package chess.controller.commands;
import java.util.ArrayList;
import java.util.List;
import chess.controller.Command;
import chess.controller.event.GameListener;
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, GameListener 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;
}
}