Splitter opp moveConveyorBelts for bedre leselighet

This commit is contained in:
Kristian Knarvik 2020-03-16 19:46:00 +01:00
parent ee753764eb
commit 49ee7dc896

View File

@ -263,21 +263,33 @@ public class RoboRallyGame implements IDrawableGame {
Tile nextTile = gameBoard.getTileOnPosition(newPosition); Tile nextTile = gameBoard.getTileOnPosition(newPosition);
Direction currentDirection = conveyorBeltTile.getDirection(); Direction currentDirection = conveyorBeltTile.getDirection();
Direction nextDirection = nextTile.getDirection();
RobotID robot = gameBoard.getRobotOnPosition(conveyorBeltPosition); RobotID robot = gameBoard.getRobotOnPosition(conveyorBeltPosition);
//TODO: Check whether the robot is able to move before moving. Alternatively: Save position and direction //TODO: Check whether the robot is able to move before moving. Alternatively: Save position and direction
// of each robot and revert if a collision is found. // of each robot and revert if a collision is found.
sleep(); doConveyorBeltMovement(robot, currentDirection, nextTile);
gameBoard.moveRobot(robot, currentDirection); }
if (testPredicate(conveyorBelts, (container) -> container.getObject() == nextTile)) { }
if (Direction.getRightRotatedDirection(nextDirection) == currentDirection) {
sleep(); /**
gameBoard.rotateRobotLeft(robot); * Moves a robot standing on a conveyor belt
} else if (Direction.getLeftRotatedDirection(nextDirection) == currentDirection) { * @param robot The id of the robot to move
sleep(); * @param currentDirection The direction of the conveyor belt the robot is standing on
gameBoard.rotateRobotRight(robot); * @param nextTile The tile the robot is moving to
} * @throws InterruptedException If disturbed during sleep
*/
private void doConveyorBeltMovement(RobotID robot, Direction currentDirection, Tile nextTile)
throws InterruptedException {
Direction nextDirection = nextTile.getDirection();
sleep();
gameBoard.moveRobot(robot, currentDirection);
if (testPredicate(conveyorBelts, (container) -> container.getObject() == nextTile)) {
if (Direction.getRightRotatedDirection(nextDirection) == currentDirection) {
sleep();
gameBoard.rotateRobotLeft(robot);
} else if (Direction.getLeftRotatedDirection(nextDirection) == currentDirection) {
sleep();
gameBoard.rotateRobotRight(robot);
} }
} }
} }