Update RoboRallyGame.java

Legger til funksjonalitet for at en robot bare kan registrere besøk på ett flagg hver runde.

Co-Authored-By: gabrielmagnus <gabrielmagnus@users.noreply.github.com>
This commit is contained in:
torlunjen 2020-04-09 19:57:29 +02:00
parent 9f843b8db6
commit af1daebd15

View File

@ -216,6 +216,16 @@ public class RoboRallyGame implements IDrawableGame {
// TODO: If this player is in power down, ask if it shall continue // TODO: If this player is in power down, ask if it shall continue
// Respawn dead robots, as long as they have more lives left // Respawn dead robots, as long as they have more lives left
respawnRobots(); respawnRobots();
resetHasTouchedFlagThisTurnForAllRobots();
}
/**
* Resets the boolean for if the robot has touched a flag this turn, to set up the next turn.
*/
private void resetHasTouchedFlagThisTurnForAllRobots() {
for (Robot robot : gameBoard.getAliveRobots()) {
robot.setHasTouchedFlagThisTurn(false);
}
} }
/** /**
@ -462,8 +472,14 @@ public class RoboRallyGame implements IDrawableGame {
for (BoardElementContainer<Tile> flag:listOfFlags) { for (BoardElementContainer<Tile> flag:listOfFlags) {
Position flagPosition = flag.getPosition(); Position flagPosition = flag.getPosition();
if (gameBoard.hasRobotOnPosition(flagPosition)) { if (gameBoard.hasRobotOnPosition(flagPosition)) {
RobotID robot = gameBoard.getRobotOnPosition(flagPosition); RobotID robotID = gameBoard.getRobotOnPosition(flagPosition);
gameBoard.updateFlagOnRobot(robot, flag.getElement().getTileType()); for (Robot robot : gameBoard.getAliveRobots()) {
if (robot.getRobotId() != robotID || robot.isHasTouchedFlagThisTurn()) {
continue;
}
gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType());
robot.setHasTouchedFlagThisTurn(true);
}
} }
} }
} }