From 019515e7a02a2e0f6de0ecf36343d1673a152925 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 12:14:51 +0100 Subject: [PATCH] refactoring: add set player ad cardDraw --- src/main/java/de/hsfulda/onses/services/GameService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index fc4edf3..668c177 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -54,7 +54,8 @@ public class GameService { player = game.getPlayerService().getPlayerList().getLast(); } for (int i = 0; i < amount; i++) { - player.getPlayerDeck().add(game.getDrawCardDeck().getFirst().setFacedown(isFaceDown)); + Card newCard = game.getDrawCardDeck().getFirst().setFacedown(isFaceDown).setPlayer(player); + player.getPlayerDeck().add(newCard); game.getDrawCardDeck().removeFirst(); } if (amount == 1 && !player.getPlayerDeck().isEmpty()) { @@ -133,6 +134,9 @@ public class GameService { } public void playCard(Card card) { + if(card.getPlayer() != null) { + card.getPlayer().removeCardFromPlayerDeck(card); + } // add lastPlayedCard back to drawCardDeck this.addLastPlayedCardToDrawCardDeck(); game.setLastPlayedCard(card);