diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2017-05-15 22:32:36 +0200 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2017-05-15 22:32:36 +0200 |
commit | 190efcd100a697165946330023fb5979bf971901 (patch) | |
tree | c14f75de1cea24735841bd46eb5fd283feeaba89 /backend/src/main | |
parent | Add test for Lobby owner index (diff) | |
download | seven-wonders-190efcd100a697165946330023fb5979bf971901.tar.gz seven-wonders-190efcd100a697165946330023fb5979bf971901.tar.bz2 seven-wonders-190efcd100a697165946330023fb5979bf971901.zip |
Add tests for lobby and game fields in Player
Diffstat (limited to 'backend/src/main')
-rw-r--r-- | backend/src/main/java/org/luxons/sevenwonders/controllers/GameBrowserController.java | 2 | ||||
-rw-r--r-- | backend/src/main/java/org/luxons/sevenwonders/lobby/Lobby.java | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/backend/src/main/java/org/luxons/sevenwonders/controllers/GameBrowserController.java b/backend/src/main/java/org/luxons/sevenwonders/controllers/GameBrowserController.java index 23b03127..dca77465 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/controllers/GameBrowserController.java +++ b/backend/src/main/java/org/luxons/sevenwonders/controllers/GameBrowserController.java @@ -61,7 +61,6 @@ public class GameBrowserController { Player gameOwner = playerRepository.find(principal.getName()); Lobby lobby = lobbyRepository.create(action.getGameName(), gameOwner); - gameOwner.setLobby(lobby); logger.info("Game '{}' ({}) created by {} ({})", lobby.getName(), lobby.getId(), gameOwner.getDisplayName(), gameOwner.getUsername()); @@ -80,7 +79,6 @@ public class GameBrowserController { Lobby lobby = lobbyRepository.find(action.getGameId()); Player newPlayer = playerRepository.find(principal.getName()); lobby.addPlayer(newPlayer); - newPlayer.setLobby(lobby); logger.info("Player '{}' ({}) joined game {}", newPlayer.getDisplayName(), newPlayer.getUsername(), lobby.getName()); diff --git a/backend/src/main/java/org/luxons/sevenwonders/lobby/Lobby.java b/backend/src/main/java/org/luxons/sevenwonders/lobby/Lobby.java index 2081d531..1cd5b3ae 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/lobby/Lobby.java +++ b/backend/src/main/java/org/luxons/sevenwonders/lobby/Lobby.java @@ -68,6 +68,7 @@ public class Lobby { throw new PlayerNameAlreadyUsedException(player.getDisplayName()); } player.setIndex(players.size()); + player.setLobby(this); players.add(player); } @@ -88,7 +89,9 @@ public class Lobby { throw new PlayerUnderflowException(gameDefinition.getMinPlayers()); } state = State.PLAYING; - return gameDefinition.initGame(id, settings, players.size()); + Game game = gameDefinition.initGame(id, settings, players.size()); + players.forEach(p -> p.setGame(game)); + return game; } private boolean hasEnoughPlayers() { @@ -123,6 +126,9 @@ public class Lobby { public void removePlayer(String username) throws UnknownPlayerException { Player player = getPlayer(players, username); players.remove(player); + player.setIndex(-1); + player.setLobby(null); + player.setGame(null); } static class GameAlreadyStartedException extends IllegalStateException { |