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