Fix: update GameService to support server commands

Refs #52
This commit is contained in:
Julian Kropff
2026-04-12 10:58:54 +02:00
parent 869f061d86
commit 8f3d0ab8a9
@@ -39,6 +39,7 @@ public class GameService {
* @return The current GameState object representing the state of the game. * @return The current GameState object representing the state of the game.
*/ */
public int getPot() { public int getPot() {
ensureState();
return state.pot; return state.pot;
} }
@@ -48,6 +49,7 @@ public class GameService {
* @return The current GameState object representing the state of the game. * @return The current GameState object representing the state of the game.
*/ */
public List<Card> getCommunityCards() { public List<Card> getCommunityCards() {
ensureState();
return state.communityCards; return state.communityCards;
} }
@@ -57,6 +59,7 @@ public class GameService {
* @return A list of Player objects representing the players in the current game state. * @return A list of Player objects representing the players in the current game state.
*/ */
public List<Player> getPlayers() { public List<Player> getPlayers() {
ensureState();
return state.players; return state.players;
} }
@@ -98,10 +101,19 @@ public class GameService {
* yet. * yet.
*/ */
public Player getWinner() { public Player getWinner() {
ensureState();
if (state.winnerIndex < 0) { if (state.winnerIndex < 0) {
return null; return null;
} }
return state.players.get(state.winnerIndex); 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");
}
}
} }