diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 3414d49..5ab22dc 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -251,7 +251,7 @@ public class Board { * @param position The position to check * @return The robot id of the robot on the position or null if there is no robot there */ - private RobotID getRobotOnPosition(Position position) { + RobotID getRobotOnPosition(Position position) { for (RobotID robotID : robots.keySet()) { Robot robot = robots.get(robotID); if (position.equals(robot.getPosition())) { @@ -266,7 +266,7 @@ public class Board { * @param position The position to check * @return True if there is a robot on the specified position */ - private boolean hasRobotOnPosition(Position position) { + boolean hasRobotOnPosition(Position position) { return getRobotOnPosition(position) != null; } diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index f56c624..3024908 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -3,6 +3,7 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.element_properties.Action; import inf112.fiasko.roborally.element_properties.Position; import inf112.fiasko.roborally.element_properties.RobotID; +import inf112.fiasko.roborally.element_properties.TileType; import inf112.fiasko.roborally.utility.BoardLoaderUtil; import java.io.IOException; @@ -182,4 +183,28 @@ public class RoboRallyGame implements IDrawableGame { sleep(); gameBoard.moveRobotForward(robotID); } -} + + /** + * Rotates all robots that are standing on cogWheel tiles on the board. + * @throws InterruptedException If interrupted while sleeping. + */ + private void rotateCogwheels() throws InterruptedException { + List> cogWheelsLeft = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT); + List> cogWheelsRight = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT); + + for (BoardElementContainer cogLeft : cogWheelsLeft) { + if (!gameBoard.hasRobotOnPosition(cogLeft.getPosition())) { + return; + } + sleep(); + makeMove(gameBoard.getRobotOnPosition(cogLeft.getPosition()), Action.ROTATE_LEFT); + } + for (BoardElementContainer cogRight : cogWheelsRight) { + if (!gameBoard.hasRobotOnPosition(cogRight.getPosition())) { + return; + } + sleep(); + makeMove(gameBoard.getRobotOnPosition(cogRight.getPosition()), Action.ROTATE_RIGHT); + } + } +} \ No newline at end of file