Endrer checkAllFlags til å bruke hjelpemetoder fra Board

This commit is contained in:
GabrielMagnus 2020-04-16 12:36:33 +02:00
parent d8167ba250
commit 4ddc2a1a83

View File

@ -554,31 +554,46 @@ public class RoboRallyGame implements IRoboRallyGame {
TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4); TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
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 robotID = gameBoard.getRobotOnPosition(flagPosition); continue;
for (Robot robot : gameBoard.getAliveRobots()) { }
if (robot.getRobotId() != robotID || robot.isHasTouchedFlagThisTurn()) { RobotID robotID = gameBoard.getRobotOnPosition(flagPosition);
continue; if (gameBoard.isHasTouchedFlagThisTurnFromRobotID(robotID)) {
} continue;
gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType()); }
robot.setHasTouchedFlagThisTurn(true); gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType());
if (victoryCheck(robot.getLastFlagVisited(), listOfFlags.size())) { gameBoard.setHasTouchedFlagThisTurnFromRobotID(robotID,true);
for (Player player : playerList) { checkIfPlayerWon(robotID, listOfFlags.size());
if (player.getRobotID() != robotID) { }
continue; }
}
setWinningPlayerName(player.getName()); /**
setGameState(GameState.GAME_IS_WON); * Checks if the player won, and shows the victory screen
} * @param robotID The robot to be checked
} * @param numberOfFlags The number of flags on the map
*/
private void checkIfPlayerWon(RobotID robotID, int numberOfFlags) {
if (victoryCheck(gameBoard.getLastFlagVisitedFromRobotID(robotID), numberOfFlags)) {
for (Player player : playerList) {
if (player.getRobotID() != robotID) {
continue;
} }
setWinningPlayerName(player.getName());
setGameState(GameState.GAME_IS_WON);
} }
} }
} }
/**
* Checks if last flag visited is the last flag
* @param lastFlagVisited The last flag a robot visited
* @param lastFlag The last flag on the map
* @return If the robot won
*/
private boolean victoryCheck(int lastFlagVisited, int lastFlag) { private boolean victoryCheck(int lastFlagVisited, int lastFlag) {
return (lastFlagVisited == lastFlag); return (lastFlagVisited == lastFlag);
} }
/** /**
* Fires all lasers on the game board * Fires all lasers on the game board
*/ */