Adds method to rotate robots standing cogwheels

This commit is contained in:
torlunjen 2020-03-12 11:49:14 +01:00
parent 7e37fbdce9
commit 9ebd5e3af0
2 changed files with 28 additions and 3 deletions

View File

@ -251,7 +251,7 @@ public class Board {
* @param position The position to check * @param position The position to check
* @return The robot id of the robot on the position or null if there is no robot there * @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()) { for (RobotID robotID : robots.keySet()) {
Robot robot = robots.get(robotID); Robot robot = robots.get(robotID);
if (position.equals(robot.getPosition())) { if (position.equals(robot.getPosition())) {
@ -266,7 +266,7 @@ public class Board {
* @param position The position to check * @param position The position to check
* @return True if there is a robot on the specified position * @return True if there is a robot on the specified position
*/ */
private boolean hasRobotOnPosition(Position position) { boolean hasRobotOnPosition(Position position) {
return getRobotOnPosition(position) != null; return getRobotOnPosition(position) != null;
} }

View File

@ -3,6 +3,7 @@ package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.element_properties.Action; import inf112.fiasko.roborally.element_properties.Action;
import inf112.fiasko.roborally.element_properties.Position; import inf112.fiasko.roborally.element_properties.Position;
import inf112.fiasko.roborally.element_properties.RobotID; import inf112.fiasko.roborally.element_properties.RobotID;
import inf112.fiasko.roborally.element_properties.TileType;
import inf112.fiasko.roborally.utility.BoardLoaderUtil; import inf112.fiasko.roborally.utility.BoardLoaderUtil;
import java.io.IOException; import java.io.IOException;
@ -182,4 +183,28 @@ public class RoboRallyGame implements IDrawableGame {
sleep(); sleep();
gameBoard.moveRobotForward(robotID); 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<BoardElementContainer<Tile>> cogWheelsLeft = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT);
List<BoardElementContainer<Tile>> cogWheelsRight = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT);
for (BoardElementContainer<Tile> cogLeft : cogWheelsLeft) {
if (!gameBoard.hasRobotOnPosition(cogLeft.getPosition())) {
return;
}
sleep();
makeMove(gameBoard.getRobotOnPosition(cogLeft.getPosition()), Action.ROTATE_LEFT);
}
for (BoardElementContainer<Tile> cogRight : cogWheelsRight) {
if (!gameBoard.hasRobotOnPosition(cogRight.getPosition())) {
return;
}
sleep();
makeMove(gameBoard.getRobotOnPosition(cogRight.getPosition()), Action.ROTATE_RIGHT);
}
}
} }