27 lines
900 B
Java
27 lines
900 B
Java
|
package laboratoire4;
|
||
|
|
||
|
public class Pushed extends Pawn {
|
||
|
public Pushed(PawnColor color, int col, int row) {
|
||
|
super(color, col, row);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isMoveValid(PusherBoard game, PawnMovement movement) {
|
||
|
Pawn[][] board = game.getBoard();
|
||
|
Pawn pusher = null;
|
||
|
Pawn to = board[row + 1][col + movement.getMove()];
|
||
|
|
||
|
if (col > 0 && movement == PawnMovement.RIGHT_DIAGONAL) {
|
||
|
pusher = board[row - 1][col - 1];
|
||
|
} else if (col < board.length - 1 && movement == PawnMovement.LEFT_DIAGONAL) {
|
||
|
pusher = board[row - 1][col + 1];
|
||
|
} else if (movement == PawnMovement.STRAIGHT) {
|
||
|
pusher = board[row - 1][col];
|
||
|
}
|
||
|
|
||
|
boolean pusherValid = pusher != null;
|
||
|
boolean destinationValid = to == null || to.color != this.color;
|
||
|
return pusherValid && destinationValid;
|
||
|
}
|
||
|
}
|