From fa81f24f0e42a87c9bdf3cba049743074d0f4681 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Wed, 7 Feb 2024 16:42:26 +0100 Subject: [PATCH 1/7] implement FaceDown to Game.java --- src/main/java/de/hsfulda/onses/models/Game.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); } From 726b71baa3513fefda4869c62eff539046ff05cf Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Wed, 7 Feb 2024 16:46:34 +0100 Subject: [PATCH 2/7] implement FaceDown to GameService.java --- .../de/hsfulda/onses/services/GameService.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 129790f..a996b0b 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -43,14 +43,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()) { @@ -73,7 +75,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() { @@ -167,15 +169,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)); } } From b17564b07d84c3a5b6cb225c5f3fa620ffb9df9b Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Wed, 7 Feb 2024 16:49:45 +0100 Subject: [PATCH 3/7] Test.CheckIfCardsInDrawCardDeckAreFaceDown --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index de47a5e..acefad7 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -474,4 +474,14 @@ public class GameServiceTest { assertTrue(answer); } + + @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()); + } + } } From 135ff27590d6b2b1be6e1a669919782652d4d5f7 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Wed, 7 Feb 2024 16:51:56 +0100 Subject: [PATCH 4/7] Test.CheckIfCardsInPlayerDeckAreFaceUp --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index acefad7..02dff9b 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -484,4 +484,14 @@ public class GameServiceTest { 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()); + } + } } From f24334bc2a79a0ce7313fca55a70d9c54ec1c50b Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Wed, 7 Feb 2024 16:52:54 +0100 Subject: [PATCH 5/7] Test.CheckIfCardsInBotDeckAreFaceDown --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 02dff9b..df554ba 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -494,4 +494,14 @@ public class GameServiceTest { 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()); + } + } } From 9284d001e853935271c286378d4a8e3c19436bc8 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Wed, 7 Feb 2024 16:57:19 +0100 Subject: [PATCH 6/7] Test.CheckIfCardsPlayedByBotWillTurnFaceUp --- .../java/de/hsfulda/onses/GameServiceTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index df554ba..a27b039 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -504,4 +504,21 @@ public class GameServiceTest { 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()); + } } From 1d3a2415498fd9cfe10b4a9d00f3ca94154c6655 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Wed, 7 Feb 2024 17:00:47 +0100 Subject: [PATCH 7/7] Test.CheckIfCardsMovedToDrawCardDeckWillBeFaceDown --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index a27b039..161d8dc 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -521,4 +521,17 @@ public class GameServiceTest { 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()); + } }