From da40f493440a9bb5109b5d3f68f4123619c2cdff Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 18:23:13 +0100 Subject: [PATCH] refactoring: convertCheckForWinIntoFunction --- .../de/hsfulda/onses/services/GameService.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index b21c590..c098f88 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -59,6 +59,14 @@ public class GameService { game.changeLastPlayedCardColor(color); } + public void checkForWin() { + if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty()) { + System.out.println("Player wins"); + } else if (this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { + System.out.println("Bot wins"); + } + } + public void playCard(Card card) { // add lastPlayedCard back to drawCardDeck this.addLastPlayedCardToDrawCardDeck(); @@ -89,11 +97,7 @@ public class GameService { drawCard(2); break; } - if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty()) { - System.out.println("Player wins"); - } else if (this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { - System.out.println("Bot wins"); - } + checkForWin(); } public boolean legalMove(Card card) {