mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
Refaktorerer moveConveyorBelts() for bedre leselighet
This commit is contained in:
parent
1667e72113
commit
b2f8abd28c
@ -296,6 +296,31 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
Direction conveyorBeltDirection = conveyorBelt.getElement().getDirection();
|
Direction conveyorBeltDirection = conveyorBelt.getElement().getDirection();
|
||||||
if (gameBoard.conveyorBeltCanMove(conveyorBelt) &&
|
if (gameBoard.conveyorBeltCanMove(conveyorBelt) &&
|
||||||
gameBoard.hasRobotOnPosition(conveyorBeltPosition)) {
|
gameBoard.hasRobotOnPosition(conveyorBeltPosition)) {
|
||||||
|
updateConveyorBeltMaps(conveyorBeltPosition, conveyorBeltDirection, newPositions, moveNormally);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Updates position for all robots affected by conveyor belts
|
||||||
|
for (RobotID robotID : RobotID.values()) {
|
||||||
|
if (newPositions.get(robotID) == null || moveNormally.get(robotID) == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (moveNormally.get(robotID)) {
|
||||||
|
gameBoard.moveRobot(robotID, gameBoard.getTileOnPosition(newPositions.get(robotID)).getDirection());
|
||||||
|
} else {
|
||||||
|
gameBoard.teleportRobot(robotID, newPositions.get(robotID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates maps containing information about what a robot on a conveyor belt should do
|
||||||
|
* @param conveyorBeltPosition The position of the conveyor belt the robot stands on
|
||||||
|
* @param conveyorBeltDirection The direction of the conveyor belt the robot stands on
|
||||||
|
* @param newPositions The map containing new positions for robots
|
||||||
|
* @param moveNormally The map containing whether a robot should move normally following normal rules
|
||||||
|
*/
|
||||||
|
private void updateConveyorBeltMaps(Position conveyorBeltPosition, Direction conveyorBeltDirection,
|
||||||
|
Map<RobotID, Position> newPositions, Map<RobotID, Boolean> moveNormally) {
|
||||||
RobotID robotAtConveyorBelt = gameBoard.getRobotOnPosition(conveyorBeltPosition);
|
RobotID robotAtConveyorBelt = gameBoard.getRobotOnPosition(conveyorBeltPosition);
|
||||||
Position newPosition = gameBoard.getNewPosition(conveyorBeltPosition, conveyorBeltDirection);
|
Position newPosition = gameBoard.getNewPosition(conveyorBeltPosition, conveyorBeltDirection);
|
||||||
if (gameBoard.isConveyorBelt(gameBoard.getTileOnPosition(newPosition))) {
|
if (gameBoard.isConveyorBelt(gameBoard.getTileOnPosition(newPosition))) {
|
||||||
@ -312,19 +337,6 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
moveNormally.put(robotAtConveyorBelt, true);
|
moveNormally.put(robotAtConveyorBelt, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//Updates position for all robots affected by conveyor belts
|
|
||||||
for (RobotID robotID : RobotID.values()) {
|
|
||||||
if (newPositions.get(robotID) == null || moveNormally.get(robotID) == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (moveNormally.get(robotID)) {
|
|
||||||
gameBoard.moveRobot(robotID, gameBoard.getTileOnPosition(newPositions.get(robotID)).getDirection());
|
|
||||||
} else {
|
|
||||||
gameBoard.teleportRobot(robotID, newPositions.get(robotID));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks all flags for robots. Tries to update the flag of the robot.
|
* Checks all flags for robots. Tries to update the flag of the robot.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user