From ec91d12c76b1b855251a03c961363ac44de3fb48 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Tue, 6 Feb 2024 21:22:27 +0100 Subject: [PATCH 1/4] add gameOver to Game --- src/main/java/de/hsfulda/onses/models/Game.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index 6a64133..5072b7c 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -10,6 +10,8 @@ public class Game { private GameService gameService; private PlayerService playerService; + private boolean gameOver; + private final ArrayList drawCardDeck = new ArrayList<>(); private Card lastPlayedCard = null; @@ -56,4 +58,12 @@ public class Game { { this.playerService = new PlayerService().setGame(this); } + + public void setGameOver(boolean gameOver) { + this.gameOver = gameOver; + } + + public boolean getGameOver() { + return gameOver; + } } From 2ebe20e6129ddcd1d492c3e0107bb34068784d3a Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Tue, 6 Feb 2024 21:25:24 +0100 Subject: [PATCH 2/4] refactoring: change checkWin --- src/main/java/de/hsfulda/onses/models/Game.java | 2 +- src/main/java/de/hsfulda/onses/services/GameService.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index 5072b7c..893fbb2 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -10,7 +10,7 @@ public class Game { private GameService gameService; private PlayerService playerService; - private boolean gameOver; + private boolean gameOver = false; private final ArrayList drawCardDeck = new ArrayList<>(); diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index ea8824f..129790f 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -108,10 +108,8 @@ public class GameService { } 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"); + if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty() || this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { + this.game.setGameOver(true); } } From 88881eaf9714ca1aa187ce91afdfc12c81c97e6e Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Tue, 6 Feb 2024 21:32:51 +0100 Subject: [PATCH 3/4] Test.CheckForGetGameOver --- src/test/java/de/hsfulda/onses/GameTest.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/hsfulda/onses/GameTest.java b/src/test/java/de/hsfulda/onses/GameTest.java index 10b0dc8..fe8fc6a 100644 --- a/src/test/java/de/hsfulda/onses/GameTest.java +++ b/src/test/java/de/hsfulda/onses/GameTest.java @@ -2,6 +2,7 @@ package de.hsfulda.onses; import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Game; +import de.hsfulda.onses.services.GameService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -46,6 +47,7 @@ public class GameTest { assertEquals(game.getDrawCardDeck().getFirst(), answer1); assertEquals(game.getDrawCardDeck().get(1), answer2); } + @Test @DisplayName("RelationshipGame_PlayerService") public void RelationshipGame_PlayerService() { @@ -56,4 +58,14 @@ public class GameTest { // assert assertEquals(expected, answer); } -} + + @Test + @DisplayName("CheckForGetGameOver") + public void CheckForGetGameOver() { + GameService gameService = new GameService(); + + boolean gameOver = gameService.getGame().getGameOver(); + + assertFalse(gameOver); + } +} \ No newline at end of file From 284104dd8b13c1b1156f435da3fab9ceeb5a4b6d Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Tue, 6 Feb 2024 21:33:48 +0100 Subject: [PATCH 4/4] Test.CheckForSetGameOver --- src/test/java/de/hsfulda/onses/GameTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/hsfulda/onses/GameTest.java b/src/test/java/de/hsfulda/onses/GameTest.java index fe8fc6a..9a0a7e0 100644 --- a/src/test/java/de/hsfulda/onses/GameTest.java +++ b/src/test/java/de/hsfulda/onses/GameTest.java @@ -5,6 +5,7 @@ import de.hsfulda.onses.models.Game; import de.hsfulda.onses.services.GameService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; public class GameTest { @@ -68,4 +69,16 @@ public class GameTest { assertFalse(gameOver); } -} \ No newline at end of file + + + @Test + @DisplayName("CheckForSetGameOver") + public void CheckForSetGameOver() { + GameService gameService = new GameService(); + + gameService.getGame().setGameOver(true); + boolean gameOver = gameService.getGame().getGameOver(); + + assertTrue(gameOver); + } +}