package laboratoire4; public class Pushed extends Pawn { public Pushed(Player player, int row, int col) { super(player, row, col); } @Override public boolean isPusher() { return false; } @Override public boolean isMoveReallyValid(IPawn[][] board, PawnMovement movement) { int direction = getDirection(); IPawn pusher = null; IPawn to = board[row + direction][col + movement.getMove()]; if (col > 0 && movement == PawnMovement.RIGHT_DIAGONAL) { pusher = board[row - direction][col - movement.getMove()]; } else if (col < board.length - 1 && movement == PawnMovement.LEFT_DIAGONAL) { pusher = board[row - direction][col - movement.getMove()]; } else if (movement == PawnMovement.STRAIGHT) { pusher = board[row - direction][col]; } boolean pusherValid = pusher != null && pusher.isPusher() && pusher.getPlayer() == player; boolean destinationValid = to == null || (movement != PawnMovement.STRAIGHT && to.getPlayer() != this.player); return pusherValid && destinationValid; } @Override public String toString() { return String.format("Pushed{%s, %s}", player, getPosition()); } }