diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 83a403e..8b3f475 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -59,17 +59,11 @@ public class GameService { game.getDrawCardDeck().removeFirst(); } if (amount == 1 && !player.getPlayerDeck().isEmpty()) { - Card drawnCard = player.getPlayerDeck().getLast(); - - if (legalMove(drawnCard)) { - player.getPlayerService().removeCardFromPlayerDeck(drawnCard); - playCard(drawnCard); - } - else nextPlayer(); - game.getPlayerService().botMove(); + nextPlayer(); + if (!game.getPlayerService().getCurrentTurn()) game.getPlayerService().botMove(); } } - if (amount != 1) { + if (amount == 7) { nextPlayer(); } } @@ -84,32 +78,9 @@ public class GameService { public void chooseColor() { // Abfrage Farbe - Card.Color color = Card.Color.BLUE; //Vorübergehend Blau - game.changeLastPlayedCardColor(color); - - if (!game.getPlayerService().getCurrentTurn()){ - int min = 0; - int max = 3; - Random rand = new Random(); - int randomNum = rand.nextInt((max - min) + 1) + min; - switch (randomNum){ - case 0: - color = Card.Color.BLUE; - game.changeLastPlayedCardColor(color); - break; - case 1: - color = Card.Color.RED; - game.changeLastPlayedCardColor(color); - break; - case 2: - color = Card.Color.YELLOW; - game.changeLastPlayedCardColor(color); - break; - case 3: - color = Card.Color.GREEN; - game.changeLastPlayedCardColor(color); - break; - } + if (game.getPlayerService().getCurrentTurn()) { + Card.Color color = Card.Color.BLUE; //Vorübergehend Blau + game.changeLastPlayedCardColor(color); } } @@ -130,7 +101,10 @@ public class GameService { public void checkForWin() { if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty() || this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { + System.out.println("gameOver"); + System.out.println(game.getGameOver()); this.game.setGameOver(true); + System.out.println(game.getGameOver()); } } @@ -150,11 +124,11 @@ public class GameService { nextPlayer(); break; case CHOOSE: - chooseColor(); + //chooseColor(); nextPlayer(); break; case CHOOSEDRAW: - chooseColor(); + //chooseColor(); nextPlayer(); drawCard(4); break; @@ -182,8 +156,6 @@ public class GameService { if (card.getValue() == lastCard.getValue()) legalMoveFound = true; // same value - if (card.getColor() == Card.Color.BLACK) legalMoveFound = true; // Color Black - return legalMoveFound; } @@ -223,4 +195,4 @@ public class GameService { this.drawCard(7); } -} +} \ No newline at end of file diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 94b24cc..70e816d 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -6,6 +6,7 @@ import de.hsfulda.onses.models.Card; import de.hsfulda.onses.services.GameService; import java.util.ArrayList; +import java.util.Random; public class PlayerService { @@ -66,12 +67,33 @@ public class PlayerService { if (getGame().getGameService().legalMove(this.playerList.getLast().getPlayerDeck().get(i))) { Card playCard = this.playerList.getLast().getPlayerDeck().get(i); this.removeCardFromPlayerDeck(playCard); + if (playCard.getValue() == Card.Value.CHOOSE || playCard.getValue() == Card.Value.CHOOSEDRAW) + { + int min = 0; + int max = 3; + Random rand = new Random(); + int randomNum = rand.nextInt((max - min) + 1) + min; + switch (randomNum){ + case 0: + playCard.setColor(Card.Color.BLUE); + break; + case 1: + playCard.setColor(Card.Color.RED); + break; + case 2: + playCard.setColor(Card.Color.YELLOW); + break; + case 3: + playCard.setColor(Card.Color.GREEN); + break; + } + } getGame().getGameService().playCard(playCard); break; } } - if (lastPlayedCard == game.getLastPlayedCard()) { + if (lastPlayedCard == game.getLastPlayedCard() && !playerList.getLast().getPlayerDeck().isEmpty()) { game.getGameService().drawCard(1); } } -} +} \ No newline at end of file diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 0ffff9f..d46cde5 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -1,4 +1,3 @@ - package de.hsfulda.onses; import com.sun.jdi.ArrayReference; @@ -120,37 +119,6 @@ public class GameServiceTest { assertEquals(expected, answer); } - @Test - @DisplayName("legalMoveColorBlack") - public void legalMoveColorBlack() { - // arrange - Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); - boolean expected = true; - // act - GameService gameService = new GameService(); - gameService.setTest(true); - gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); - - boolean answer = gameService.legalMove(input); - // assert - assertEquals(expected, answer); - } - - @Test - @DisplayName("legalMoveColorBlackCHOOSEDRAW") - public void legalMoveColorBlackCHOOSEDRAW() { - // arrange - Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSEDRAW); - boolean expected = true; - // act - GameService gameService = new GameService(); - gameService.setTest(true); - gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FIVE)); - - boolean answer = gameService.legalMove(input); - // assert - assertEquals(expected, answer); - } @Test @DisplayName("ShuffelDeck") @@ -225,41 +193,6 @@ public class GameServiceTest { assertEquals(expected, gameService.getGame().getPlayerService().getCurrentTurn()); } - @Test - @DisplayName("ChooseTest") - public void ChooseTest() { - GameService gameService = new GameService(); - gameService.setTest(true); - boolean expected = true; - boolean answer = false; - - gameService.playCard(new Card().setValue(Card.Value.CHOOSE).setColor(Card.Color.BLACK)); - - if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { - answer = true; - } - - assertEquals(expected, answer); - - } - - @Test - @DisplayName("ChooseDrawTest") - public void ChooseDrawTest() { - GameService gameService = new GameService(); - gameService.setTest(true); - boolean expected = true; - boolean answer = false; - - gameService.playCard(new Card().setValue(Card.Value.CHOOSEDRAW).setColor(Card.Color.BLACK)); - - if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { - answer = true; - } - - assertEquals(expected, answer); - - } @Test @DisplayName("DrawByChoiceForceKeep") public void DrawByChoiceForceKeep() { @@ -323,26 +256,6 @@ public class GameServiceTest { assertEquals(expected, answer); } - @Test - @DisplayName("DrawByChoiceForcePlay") - public void DrawByChoiceForcePlay() { - - GameService gameService = new GameService(); - gameService.setTest(true); - Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); - - gameService.getGame().getDrawCardDeck().clear(); - gameService.getGame().getPlayerService().setCurrentTurn(true); - gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.SEVEN)); - gameService.getGame().addCardToDrawCardDeck(input); - gameService.getGame().getPlayerService().getPlayerList().getFirst().addCardToPlayerDeck(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.TWO)); - gameService.drawCard(1); - - Card answer = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().getLast(); - - assertNotEquals(input, answer); - } - @Test @DisplayName("CheckThatBotDeckHasSevenCardsAfterGameStart") public void CheckThatBotDeckHasSevenCardsAfterGameStart() { @@ -436,7 +349,7 @@ public class GameServiceTest { gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().add(card); gameService.getGame().getPlayerService().setCurrentTurn(false); - gameService.playCard(card); + gameService.getGame().getPlayerService().botMove(); if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK){ answer = true; @@ -565,4 +478,4 @@ public class GameServiceTest { boolean expected = true; assertEquals(expected, answer); } -} +} \ No newline at end of file