2023-03-20 17:41:13 -04:00
|
|
|
package laboratoire4;
|
|
|
|
|
|
|
|
public class Pushed extends Pawn {
|
2023-03-21 18:06:17 -04:00
|
|
|
public Pushed(Player player, int row, int col) {
|
|
|
|
super(player, row, col);
|
2023-03-20 17:41:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-03-24 14:36:13 -04:00
|
|
|
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()];
|
2023-03-20 17:41:13 -04:00
|
|
|
|
|
|
|
if (col > 0 && movement == PawnMovement.RIGHT_DIAGONAL) {
|
2023-03-24 14:36:13 -04:00
|
|
|
pusher = board[row - direction][col - movement.getMove()];
|
2023-03-20 17:41:13 -04:00
|
|
|
} else if (col < board.length - 1 && movement == PawnMovement.LEFT_DIAGONAL) {
|
2023-03-24 14:36:13 -04:00
|
|
|
pusher = board[row - direction][col - movement.getMove()];
|
2023-03-20 17:41:13 -04:00
|
|
|
} else if (movement == PawnMovement.STRAIGHT) {
|
2023-03-21 18:06:17 -04:00
|
|
|
pusher = board[row - direction][col];
|
2023-03-20 17:41:13 -04:00
|
|
|
}
|
|
|
|
|
2023-03-24 14:36:13 -04:00
|
|
|
boolean pusherValid = pusher != null && pusher.isPusher() && pusher.getPlayer() == player;
|
|
|
|
boolean destinationValid = to == null || (movement != PawnMovement.STRAIGHT && to.getPlayer() != this.player);
|
2023-03-20 17:41:13 -04:00
|
|
|
return pusherValid && destinationValid;
|
|
|
|
}
|
2023-03-21 18:06:17 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2023-03-24 14:36:13 -04:00
|
|
|
return String.format("Pushed{%s, %s}", player, getPosition());
|
2023-03-21 18:06:17 -04:00
|
|
|
}
|
2023-03-20 17:41:13 -04:00
|
|
|
}
|