juste better
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package chess.io.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import chess.io.Command;
|
||||
import chess.io.CommandResult;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
import chess.model.Piece;
|
||||
|
||||
public class GetAllowedMovesCommand extends Command {
|
||||
|
||||
private final Coordinate start;
|
||||
private List<Coordinate> destinations;
|
||||
|
||||
public GetAllowedMovesCommand(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;
|
||||
}
|
||||
}
|
||||
34
app/src/main/java/chess/io/commands/GetPieceAtCommand.java
Normal file
34
app/src/main/java/chess/io/commands/GetPieceAtCommand.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package chess.io.commands;
|
||||
|
||||
import chess.io.Command;
|
||||
import chess.io.CommandResult;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
import chess.model.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, OutputSystem outputSystem) {
|
||||
if (!pieceCoords.isValid())
|
||||
return CommandResult.NotAllowed;
|
||||
|
||||
this.piece = game.getBoard().pieceAt(pieceCoords);
|
||||
|
||||
return CommandResult.NotMoved;
|
||||
}
|
||||
|
||||
public Piece getPiece() {
|
||||
return piece;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,6 +49,8 @@ public class NewGameCommand extends Command {
|
||||
|
||||
game.resetPlayerTurn();
|
||||
|
||||
outputSystem.gameStarted();
|
||||
|
||||
return CommandResult.NotMoved;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user