diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/game/GameService.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/game/GameService.java index e58c13d..896e8bf 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/game/GameService.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/game/GameService.java @@ -39,6 +39,7 @@ public class GameService { * @return The current GameState object representing the state of the game. */ public int getPot() { + ensureState(); return state.pot; } @@ -48,6 +49,7 @@ public class GameService { * @return The current GameState object representing the state of the game. */ public List getCommunityCards() { + ensureState(); return state.communityCards; } @@ -57,6 +59,7 @@ public class GameService { * @return A list of Player objects representing the players in the current game state. */ public List getPlayers() { + ensureState(); return state.players; } @@ -98,10 +101,19 @@ public class GameService { * yet. */ public Player getWinner() { + ensureState(); + if (state.winnerIndex < 0) { return null; } return state.players.get(state.winnerIndex); } + + /** Ensure that the game state has been initialized before accessing it. */ + private void ensureState() { + if (state == null) { + throw new IllegalStateException("Call refresh() first"); + } + } }