Browse Source

Merge branch 'addGameOver' into 'main'

Add game over

See merge request fdai7736/onses!22
main
fdai7793 11 months ago
parent
commit
f46ec5bedc
  1. 10
      src/main/java/de/hsfulda/onses/models/Game.java
  2. 6
      src/main/java/de/hsfulda/onses/services/GameService.java
  3. 25
      src/test/java/de/hsfulda/onses/GameTest.java

10
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<Card> 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);

6
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);
}
}

25
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);
}
}
Loading…
Cancel
Save