LOG320_Lab4/src/main/java/laboratoire4/Pushed.java

27 lines
900 B
Java
Raw Normal View History

2023-03-20 17:41:13 -04:00
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;
}
}