diff options
Diffstat (limited to 'backend/src/main/java')
-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 { |