From 8f3d0ab8a983385ce3ed62246962cda5f397ef92 Mon Sep 17 00:00:00 2001 From: Julian Kropff Date: Sun, 12 Apr 2026 10:58:54 +0200 Subject: [PATCH] Fix: update GameService to support server commands Refs #52 --- .../dbis/cs108/casono/client/game/GameService.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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"); + } + } }