mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Adds method to rotate robots standing cogwheels
This commit is contained in:
parent
7e37fbdce9
commit
9ebd5e3af0
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user