Oppdaterer RoboRallyGame slik at roboter starter på korrekt posisjon

This commit is contained in:
Kristian Knarvik 2020-04-17 12:07:26 +02:00
parent 29261f037f
commit c650554d81

View File

@ -27,9 +27,9 @@ public class RoboRallyGame implements IRoboRallyGame {
private final boolean host; private final boolean host;
private Deck<ProgrammingCard> mainDeck; private Deck<ProgrammingCard> mainDeck;
private GameState gameState = GameState.BEGINNING_OF_GAME; private GameState gameState = GameState.BEGINNING_OF_GAME;
private String playerName; private final String playerName;
private final RoboRallyClient client; private final RoboRallyClient client;
private RoboRallyServer server; private final RoboRallyServer server;
private String winningPlayerName; private String winningPlayerName;
private List<ProgrammingCard> program; private List<ProgrammingCard> program;
private ProgrammingCardDeck playerHand; private ProgrammingCardDeck playerHand;
@ -172,6 +172,7 @@ public class RoboRallyGame implements IRoboRallyGame {
repairAllRobotsOnRepairTiles(); repairAllRobotsOnRepairTiles();
//Updates the host's card deck //Updates the host's card deck
if (host) { if (host) {
//TODO: Fix updateLockedProgrammingCardsForAllPlayers throwing NullPointerException on robotDamage
updateLockedProgrammingCardsForAllPlayers(); updateLockedProgrammingCardsForAllPlayers();
removeNonLockedProgrammingCardsFromPlayers(); removeNonLockedProgrammingCardsFromPlayers();
} }
@ -231,6 +232,7 @@ public class RoboRallyGame implements IRoboRallyGame {
} }
gameBoard = BoardLoaderUtil.loadBoard("boards/" + boardName, robots); gameBoard = BoardLoaderUtil.loadBoard("boards/" + boardName, robots);
moveRobotsToSpawn();
repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3, repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3,
TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER); 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<BoardElementContainer<Tile>> spawnTileContainerList = gameBoard.getPositionsOfTileOnBoard(robotSpawn);
if (spawnTileContainerList.size() != 1) {
throw new IllegalArgumentException("The chosen board seems to be missing a robot spawn");
}
BoardElementContainer<Tile> spawnTileContainer = spawnTileContainerList.get(0);
gameBoard.teleportRobot(robotID, spawnTileContainer.getPosition());
}
}
/** /**
* Runs all the steps of one turn in the game * Runs all the steps of one turn in the game
*/ */