From ddfb8e271b264e589e5e036c584f9c5929c60718 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:22:28 +0100 Subject: [PATCH] unable to draw from empty DrawCardDeck --- .../de/hsfulda/onses/services/GameService.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 2514ae7..f7618f7 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -32,14 +32,16 @@ public class GameService { public void drawCard(int amount) { Player player = null; - if (game.getPlayerService().getCurrentTurn()) { - player = game.getPlayerService().getPlayerList().getFirst(); - } else { - player = game.getPlayerService().getPlayerList().getLast(); - } - for (int i = 0; i < amount; i++) { - player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); - game.getDrawCardDeck().removeFirst(); + if (!game.getDrawCardDeck().isEmpty()) { + if (game.getPlayerService().getCurrentTurn()) { + player = game.getPlayerService().getPlayerList().getFirst(); + } else { + player = game.getPlayerService().getPlayerList().getLast(); + } + for (int i = 0; i < amount; i++) { + player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); + game.getDrawCardDeck().removeFirst(); + } } if (amount != 1) { nextPlayer();