diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index 17bc16d..4683237 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -16,6 +16,8 @@ public class Game { private GameService gameService; private PlayerService playerService; + private boolean gameOver = false; + private final ArrayList drawCardDeck = new ArrayList<>(); private Card lastPlayedCard = null; @@ -67,6 +69,14 @@ public class Game { this.playerService = new PlayerService().setGame(this); } + public void setGameOver(boolean gameOver) { + this.gameOver = gameOver; + } + + public boolean getGameOver() { + return gameOver; + } + public PropertyChangeSupport listeners() { if(this.listeners == null) { this.listeners = new PropertyChangeSupport(this); 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); } } diff --git a/src/test/java/de/hsfulda/onses/GameTest.java b/src/test/java/de/hsfulda/onses/GameTest.java index 10b0dc8..9a0a7e0 100644 --- a/src/test/java/de/hsfulda/onses/GameTest.java +++ b/src/test/java/de/hsfulda/onses/GameTest.java @@ -2,8 +2,10 @@ 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.*; public class GameTest { @@ -46,6 +48,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 +59,26 @@ public class GameTest { // assert assertEquals(expected, answer); } + + @Test + @DisplayName("CheckForGetGameOver") + public void CheckForGetGameOver() { + GameService gameService = new GameService(); + + boolean gameOver = gameService.getGame().getGameOver(); + + assertFalse(gameOver); + } + + + @Test + @DisplayName("CheckForSetGameOver") + public void CheckForSetGameOver() { + GameService gameService = new GameService(); + + gameService.getGame().setGameOver(true); + boolean gameOver = gameService.getGame().getGameOver(); + + assertTrue(gameOver); + } }