Legger til pushere. Closes #45

This commit is contained in:
2020-04-24 22:43:31 +02:00
parent 4b9eadc9f2
commit 62f9ccded5
4 changed files with 52 additions and 4 deletions

View File

@@ -19,7 +19,15 @@ public enum WallType {
/**
* A wall with two lasers
*/
WALL_LASER_DOUBLE(4);
WALL_LASER_DOUBLE(4),
/**
* A pusher which pushes on every odd phase
*/
WALL_PUSHER_ODD(5),
/**
* A pusher which pushes on every even phase
*/
WALL_PUSHER_EVEN(6);
private final int wallTypeID;

View File

@@ -6,6 +6,7 @@ import inf112.fiasko.roborally.elementproperties.GameState;
import inf112.fiasko.roborally.elementproperties.Position;
import inf112.fiasko.roborally.elementproperties.RobotID;
import inf112.fiasko.roborally.elementproperties.TileType;
import inf112.fiasko.roborally.elementproperties.WallType;
import java.util.ArrayList;
import java.util.Collections;
@@ -26,6 +27,8 @@ public class Phase {
private List<BoardElementContainer<Tile>> conveyorBelts;
private List<BoardElementContainer<Tile>> fastConveyorBelts;
private List<BoardElementContainer<Tile>> flags;
private List<BoardElementContainer<Wall>> oddPushers;
private List<BoardElementContainer<Wall>> evenPushers;
/**
* Instantiates a new phase
@@ -54,12 +57,45 @@ public class Phase {
runProgrammingCards(phaseNumber);
moveAllConveyorBelts();
startPushers(phaseNumber);
rotateCogwheels();
fireAllLasers();
checkAllFlags();
}
/**
* Starts all pushers which should be pushed this phase
*
* @param phaseNumber The current phase number
* @throws InterruptedException If interrupted while sleeping
*/
private void startPushers(int phaseNumber) throws InterruptedException {
sleep();
List<BoardElementContainer<Wall>> pushersToPush;
if (phaseNumber % 2 == 0) {
pushersToPush = evenPushers;
} else {
pushersToPush = oddPushers;
}
for (BoardElementContainer<Wall> pusher : pushersToPush) {
runPusher(pusher.getPosition(), Direction.getReverseDirection(pusher.getElement().getDirection()));
}
}
/**
* Makes the pusher try to push any robot standing on it
*
* @param pusherPosition The position of the pusher which is pushing
* @param pushDirection The direction of the pusher which is pushing
*/
private void runPusher(Position pusherPosition, Direction pushDirection) {
RobotID robotToPush = gameBoard.getRobotOnPosition(pusherPosition);
if (robotToPush != null) {
gameBoard.moveRobot(robotToPush, pushDirection);
}
}
/**
* Checks all flags for robots. Tries to update the flag of the robot.
*/
@@ -335,5 +371,7 @@ public class Phase {
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
flags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
oddPushers = gameBoard.getPositionsOfWallOnBoard(WallType.WALL_PUSHER_ODD);
evenPushers = gameBoard.getPositionsOfWallOnBoard(WallType.WALL_PUSHER_EVEN);
}
}