diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 3550bae..be7db3e 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -329,6 +329,9 @@ public class Board { return true; } Position positionInFront = getNewPosition(conveyorBeltPosition, conveyorBeltDirection); + if (!isValidPosition(positionInFront)) { + return true; + } Tile tileInFront = getTileOnPosition(positionInFront); //If a conveyor belt will move the robot outside the map, the move is valid if (!isValidPosition(positionInFront)) { @@ -564,7 +567,7 @@ public class Board { * @param position The position to test * @return True if the position is valid. False otherwise */ - private boolean isValidPosition(Position position) { + public boolean isValidPosition(Position position) { return position.getXCoordinate() >= 0 && position.getXCoordinate() < boardWidth && position.getYCoordinate() >= 0 diff --git a/src/main/java/inf112/fiasko/roborally/objects/Phase.java b/src/main/java/inf112/fiasko/roborally/objects/Phase.java index 5623ab3..616d23b 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Phase.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Phase.java @@ -128,10 +128,11 @@ public class Phase { if (!gameBoard.hasRobotOnPosition(cogwheel.getPosition())) { continue; } + RobotID robotAtCogwheel = gameBoard.getRobotOnPosition(cogwheel.getPosition()); if (cogwheel.getElement().getTileType() == TileType.COGWHEEL_RIGHT) { - gameBoard.rotateRobotRight(gameBoard.getRobotOnPosition(cogwheel.getPosition())); + gameBoard.rotateRobotRight(robotAtCogwheel); } else { - gameBoard.rotateRobotLeft(gameBoard.getRobotOnPosition(cogwheel.getPosition())); + gameBoard.rotateRobotLeft(robotAtCogwheel); } } } @@ -269,7 +270,7 @@ public class Phase { Map newPositions, Map moveNormally) { RobotID robotAtConveyorBelt = gameBoard.getRobotOnPosition(conveyorBeltPosition); Position newPosition = gameBoard.getNewPosition(conveyorBeltPosition, conveyorBeltDirection); - if (gameBoard.isConveyorBelt(gameBoard.getTileOnPosition(newPosition))) { + if (gameBoard.isValidPosition(newPosition) && gameBoard.isConveyorBelt(gameBoard.getTileOnPosition(newPosition))) { newPositions.put(robotAtConveyorBelt, newPosition); moveNormally.put(robotAtConveyorBelt, false); Direction newDirection = gameBoard.getTileOnPosition(newPosition).getDirection();