From c650554d812d493238c2efdbba2bf229557dd8af Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 17 Apr 2020 12:07:26 +0200 Subject: [PATCH] =?UTF-8?q?Oppdaterer=20RoboRallyGame=20slik=20at=20robote?= =?UTF-8?q?r=20starter=20p=C3=A5=20korrekt=20posisjon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roborally/objects/RoboRallyGame.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 1a6d216..19ff2b7 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -27,9 +27,9 @@ public class RoboRallyGame implements IRoboRallyGame { private final boolean host; private Deck mainDeck; private GameState gameState = GameState.BEGINNING_OF_GAME; - private String playerName; + private final String playerName; private final RoboRallyClient client; - private RoboRallyServer server; + private final RoboRallyServer server; private String winningPlayerName; private List program; private ProgrammingCardDeck playerHand; @@ -172,6 +172,7 @@ public class RoboRallyGame implements IRoboRallyGame { repairAllRobotsOnRepairTiles(); //Updates the host's card deck if (host) { + //TODO: Fix updateLockedProgrammingCardsForAllPlayers throwing NullPointerException on robotDamage updateLockedProgrammingCardsForAllPlayers(); removeNonLockedProgrammingCardsFromPlayers(); } @@ -231,6 +232,7 @@ public class RoboRallyGame implements IRoboRallyGame { } gameBoard = BoardLoaderUtil.loadBoard("boards/" + boardName, robots); + moveRobotsToSpawn(); repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER); @@ -244,6 +246,22 @@ public class RoboRallyGame implements IRoboRallyGame { } } + /** + * Teleports all robots to their respective spawn positions + */ + private void moveRobotsToSpawn() { + for (Player player : playerList) { + RobotID robotID = player.getRobotID(); + TileType robotSpawn = TileType.getTileTypeFromID(robotID.getRobotIDID() + 22); + List> spawnTileContainerList = gameBoard.getPositionsOfTileOnBoard(robotSpawn); + if (spawnTileContainerList.size() != 1) { + throw new IllegalArgumentException("The chosen board seems to be missing a robot spawn"); + } + BoardElementContainer spawnTileContainer = spawnTileContainerList.get(0); + gameBoard.teleportRobot(robotID, spawnTileContainer.getPosition()); + } + } + /** * Runs all the steps of one turn in the game */