LOG320_Lab4/src/main/java/laboratoire4/pawns/SimulatedPushed.java
2023-04-09 13:26:32 -04:00

50 lines
1.1 KiB
Java

package laboratoire4.pawns;
import laboratoire4.Player;
import java.util.Stack;
public class SimulatedPushed extends Pushed implements SimulatedPawn {
private final int originalRow;
private final int originalCol;
private final Stack<PawnMovement> previousMoves = new Stack<>();
private int moveCount = 0;
public SimulatedPushed(Player player, int row, int col) {
super(player, row, col);
originalRow = row;
originalCol = col;
}
@Override
public void move(PawnMovement movement) {
super.move(movement);
previousMoves.push(movement);
moveCount++;
}
@Override
public void revertMove() {
PawnMovement move = previousMoves.pop();
setRow(row - getDirection());
setCol(col - move.getMove());
moveCount--;
}
@Override
public int getOriginalRow() {
return originalRow;
}
@Override
public int getOriginalCol() {
return originalCol;
}
@Override
public int getMoveCount() {
return moveCount;
}
}