diff --git a/src/main/java/inf112/fiasko/roborally/elementproperties/WallType.java b/src/main/java/inf112/fiasko/roborally/elementproperties/WallType.java index 98870f3..608b436 100644 --- a/src/main/java/inf112/fiasko/roborally/elementproperties/WallType.java +++ b/src/main/java/inf112/fiasko/roborally/elementproperties/WallType.java @@ -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; diff --git a/src/main/java/inf112/fiasko/roborally/objects/Phase.java b/src/main/java/inf112/fiasko/roborally/objects/Phase.java index 5c06a2c..2e5a4fc 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Phase.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Phase.java @@ -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> conveyorBelts; private List> fastConveyorBelts; private List> flags; + private List> oddPushers; + private List> 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> pushersToPush; + if (phaseNumber % 2 == 0) { + pushersToPush = evenPushers; + } else { + pushersToPush = oddPushers; + } + for (BoardElementContainer 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); } } diff --git a/src/main/resources/boards/all_tiles_test_board.txt b/src/main/resources/boards/all_tiles_test_board.txt index 27ff3f3..86c8478 100644 --- a/src/main/resources/boards/all_tiles_test_board.txt +++ b/src/main/resources/boards/all_tiles_test_board.txt @@ -38,6 +38,6 @@ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 1;1 1;3 1;5 1;7 2;2 2;4 2;6 2;8 -3;1 3;3 3;5 3;7 4;1 4;3 4;5 4;7 \ No newline at end of file +3;1 3;3 3;5 3;7 4;1 4;3 4;5 4;7 +5;1 5;3 5;5 5;7 6;1 6;3 6;5 6;7 \ No newline at end of file diff --git a/src/main/resources/texture_sheet_wall_mapping.txt b/src/main/resources/texture_sheet_wall_mapping.txt index 2c8ce61..d3ff803 100644 --- a/src/main/resources/texture_sheet_wall_mapping.txt +++ b/src/main/resources/texture_sheet_wall_mapping.txt @@ -1,4 +1,6 @@ WALL_NORMAL 6 3 6 2 4 3 5 3 WALL_CORNER 7 1 7 0 7 3 7 2 WALL_LASER_SINGLE 4 5 5 5 4 4 5 4 -WALL_LASER_DOUBLE 5 11 6 11 6 10 4 11 \ No newline at end of file +WALL_LASER_DOUBLE 5 11 6 11 6 10 4 11 +WALL_PUSHER_ODD 0 1 1 1 2 0 3 1 +WALL_PUSHER_EVEN 0 0 1 0 2 1 3 0 \ No newline at end of file