mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-06-27 11:44:42 +02:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
This commit is contained in:
@ -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;
|
||||
@ -15,6 +16,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class RoboRallyGame implements IDrawableGame {
|
||||
private Board gameBoard;
|
||||
List<BoardElementContainer<Tile>> cogwheels;
|
||||
|
||||
public RoboRallyGame(boolean debug) {
|
||||
if (debug) {
|
||||
@ -86,6 +88,8 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 2)));
|
||||
robots.add(new Robot(RobotID.ROBOT_3, new Position(1, 3)));
|
||||
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
|
||||
cogwheels = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT,
|
||||
TileType.COGWHEEL_LEFT);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
runGameLoop();
|
||||
@ -182,4 +186,22 @@ 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 {
|
||||
for (BoardElementContainer<Tile> cogwheel : cogwheels) {
|
||||
if (!gameBoard.hasRobotOnPosition(cogwheel.getPosition())) {
|
||||
continue;
|
||||
}
|
||||
sleep();
|
||||
if (cogwheel.obj.getTileType() == TileType.COGWHEEL_RIGHT) {
|
||||
gameBoard.rotateRobotRight(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
||||
} else {
|
||||
gameBoard.rotateRobotLeft(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user