diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index 4683237..6a9c67a 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -31,7 +31,7 @@ public class Game { } public Game setLastPlayedCard(Card lastPlayedCard) { final Card oldLastPlayedCard = this.lastPlayedCard; - this.lastPlayedCard = lastPlayedCard; + this.lastPlayedCard = lastPlayedCard.setFacedown(false); this.firePropertyChange(PROPERTY_LAST_PLAYED_CARD, oldLastPlayedCard, lastPlayedCard); return this; } @@ -42,7 +42,7 @@ public class Game { public void addCardToDrawCardDeck(Card card) { final ArrayList oldCards = new ArrayList<>(this.drawCardDeck); - drawCardDeck.add(card); + drawCardDeck.add(card.setFacedown(true)); this.firePropertyChange(PROPERTY_DRAW_CARD_DECK, oldCards, drawCardDeck); } diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 6176f7c..fc4edf3 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -45,14 +45,16 @@ public class GameService { public void drawCard(int amount) { if (!game.getDrawCardDeck().isEmpty()) { + boolean isFaceDown = false; Player player = null; if (game.getPlayerService().getCurrentTurn()) { player = game.getPlayerService().getPlayerList().getFirst(); } else { + isFaceDown = true; player = game.getPlayerService().getPlayerList().getLast(); } for (int i = 0; i < amount; i++) { - player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); + player.getPlayerDeck().add(game.getDrawCardDeck().getFirst().setFacedown(isFaceDown)); game.getDrawCardDeck().removeFirst(); } if (amount == 1 && !player.getPlayerDeck().isEmpty()) { @@ -75,7 +77,7 @@ public class GameService { if (lastCard.getValue() == Card.Value.CHOOSE || lastCard.getValue() == Card.Value.CHOOSEDRAW) { lastCard.setColor(Card.Color.BLACK); } - game.addCardToDrawCardDeck(lastCard); + game.addCardToDrawCardDeck(lastCard.setFacedown(true)); } public void chooseColor() { @@ -184,15 +186,15 @@ public class GameService { for (Card.Color i : Card.Color.values()) { for (Card.Value j : Card.Value.values()) { if (i != Card.Color.BLACK && j != Card.Value.CHOOSE && j != Card.Value.CHOOSEDRAW) { - game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j)); - game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j)); + game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j).setFacedown(true)); + game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j).setFacedown(true)); } } } for (int i = 0; i != 4; i++) { - game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE)); - game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSEDRAW)); + game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE).setFacedown(true)); + game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSEDRAW).setFacedown(true)); } } diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 0e02461..0ffff9f 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -479,6 +479,65 @@ public class GameServiceTest { } @Test + @DisplayName("CheckIfCardsInDrawCardDeckAreFaceDown") + public void CheckIfCardsInDrawCardDeckAreFaceDown() { + GameService gameService = new GameService(); + + for (int i = 0; i < gameService.getGame().getDrawCardDeck().size(); i++) { + assertTrue(gameService.getGame().getDrawCardDeck().get(i).isFacedown()); + } + } + + @Test + @DisplayName("CheckIfCardsInPlayerDeckAreFaceUp") + public void CheckIfCardsInPlayerDeckAreFaceUp() { + GameService gameService = new GameService(); + + for (int i = 0; i < gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); i++) { + assertFalse(gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().get(i).isFacedown()); + } + } + + @Test + @DisplayName("CheckIfCardsInBotDeckAreFaceDown") + public void CheckIfCardsInBotDeckAreFaceDown() { + GameService gameService = new GameService(); + + for (int i = 0; i < gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); i++) { + assertTrue(gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().get(i).isFacedown()); + } + } + + @Test + @DisplayName("CheckIfCardsPlayedByBotWillTurnFaceUp") + public void CheckIfCardsPlayedByBotWillTurnFaceUp() { + GameService gameService = new GameService(); + + Card card = new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FOUR).setFacedown(true); + + gameService.getGame().getPlayerService().setCurrentTurn(false); + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FIVE)); + gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().clear(); + gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().add(card); + + gameService.getGame().getPlayerService().botMove(); + + assertFalse(gameService.getGame().getLastPlayedCard().isFacedown()); + } + + @Test + @DisplayName("CheckIfCardsMovedToDrawCardDeckWillBeFaceDown") + public void CheckIfCardsMovedToDrawCardDeckWillBeFaceDown() { + GameService gameService = new GameService(); + + Card card = new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FOUR); + + gameService.getGame().setLastPlayedCard(card); + gameService.addLastPlayedCardToDrawCardDeck(); + + assertTrue(gameService.getGame().getDrawCardDeck().getLast().isFacedown()); + } + @DisplayName("PlaySevenPlayerDeckIsNowBotDeck") public void PlaySevenPlayerDeckIsNowBotDeck() { GameService gameService = new GameService();