From 347434e3e7e3ef2cc303237ae36138ae50821164 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 16:28:46 +0100 Subject: [PATCH 01/15] add playCard skip --- src/main/java/de/hsfulda/onses/services/GameService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index c9acd67..d786a23 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -25,6 +25,11 @@ public class GameService { // add lastPlayedCard back to drawCardDeck game.setLastPlayedCard(card); // check for special rules (draw, colorchoose, skip,...) + // Skip + if (card.getValue() == Card.Value.SKIP) { + game.getPlayerService().nextTurn(); + game.getPlayerService().nextTurn(); + } } public boolean legalMove(Player player, Card card) From 446b970efec54c9d8971589c9528821fa6f4a3da Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 16:29:28 +0100 Subject: [PATCH 02/15] Test.SkipTest --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index c76e1d4..906c5c4 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -185,4 +185,16 @@ public class GameServiceTest { assertEquals(expected, answer2); } + @Test + @DisplayName("SkipTest") + public void SkipTest () + { + GameService gameservice = new GameService(); + boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); + + gameservice.playCard(new Player(), new Card().setValue(Card.Value.SKIP).setColor(Card.Color.BLACK)); + + assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); + } + } From a8c26a1d6103264765bacd7ee19ec795ffae637b Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 16:33:02 +0100 Subject: [PATCH 03/15] refactoring: nextPlayer --- src/main/java/de/hsfulda/onses/services/GameService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index d786a23..a3d14b2 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -20,6 +20,9 @@ public class GameService { return game; } + public void nextPlayer() { + game.getPlayerService().nextTurn(); + } public void playCard(Player player, Card card) { // add lastPlayedCard back to drawCardDeck @@ -27,8 +30,8 @@ public class GameService { // check for special rules (draw, colorchoose, skip,...) // Skip if (card.getValue() == Card.Value.SKIP) { - game.getPlayerService().nextTurn(); - game.getPlayerService().nextTurn(); + nextPlayer(); + nextPlayer(); } } From a5bc6ba5925173e05c595441a5b9668b2ee0ac14 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 16:36:36 +0100 Subject: [PATCH 04/15] add playCard Reverse --- src/main/java/de/hsfulda/onses/services/GameService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index a3d14b2..072c664 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -33,6 +33,11 @@ public class GameService { nextPlayer(); nextPlayer(); } + // Reverse + if (card.getValue() == Card.Value.REVERSE) { + nextPlayer(); + nextPlayer(); + } } public boolean legalMove(Player player, Card card) From 8a36e4f173c5026a9da15bb477c7bec5d15bbcbf Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 16:38:49 +0100 Subject: [PATCH 05/15] Test.ReverseTest --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 906c5c4..c60ff9b 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -197,4 +197,16 @@ public class GameServiceTest { assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); } + @Test + @DisplayName("ReverseTest") + public void ReverseTest () + { + GameService gameservice = new GameService(); + boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); + + gameservice.playCard(new Player(), new Card().setValue(Card.Value.REVERSE).setColor(Card.Color.BLACK)); + + assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); + } + } From b10fdde6752e9f22a5bfc369f4e06d79aa59fe58 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 16:46:25 +0100 Subject: [PATCH 06/15] add Game changeLastPlayedCard --- src/main/java/de/hsfulda/onses/models/Game.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index 0f9a56c..6a64133 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -18,6 +18,9 @@ public class Game { return lastPlayedCard; } + public void changeLastPlayedCardColor(Card.Color color) { + lastPlayedCard.setColor(color); + } public Game setLastPlayedCard(Card lastPlayedCard) { this.lastPlayedCard = lastPlayedCard; return this; From e4738322a9c09b0f2364286897414964208feb23 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 16:51:14 +0100 Subject: [PATCH 07/15] add playcard Reverse --- src/main/java/de/hsfulda/onses/services/GameService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 072c664..7788995 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -38,6 +38,12 @@ public class GameService { nextPlayer(); nextPlayer(); } + // Choose + if (card.getValue() == Card.Value.CHOOSE) { + // Abfrage Farbe + Card.Color color = Card.Color.BLUE; //Vorübergehend Blau + game.changeLastPlayedCardColor(color); + } } public boolean legalMove(Player player, Card card) From 8c05b73c72e87e42b8c1d839a024a6e75760a8b4 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 17:09:53 +0100 Subject: [PATCH 08/15] Test.ChooseTest --- .../java/de/hsfulda/onses/GameServiceTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index c60ff9b..5c5fe84 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -209,4 +209,22 @@ public class GameServiceTest { assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); } + @Test + @DisplayName("ChooseTest") + public void ChooseTest () + { + GameService gameservice = new GameService(); + boolean expected = true; + boolean answer = false; + + gameservice.playCard(new Player(), new Card().setValue(Card.Value.CHOOSE).setColor(Card.Color.BLACK)); + + if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { + answer = true; + } + + assertEquals(expected, answer); + + } + } From 8e60e5ff9e791cb50bf50f93b3753254b160355d Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 17:18:08 +0100 Subject: [PATCH 09/15] add playCard Draw --- src/main/java/de/hsfulda/onses/services/GameService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 7788995..bca18b9 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -22,6 +22,9 @@ public class GameService { public void nextPlayer() { game.getPlayerService().nextTurn(); + } + public void drawCard(int amount) { + } public void playCard(Player player, Card card) { @@ -44,6 +47,12 @@ public class GameService { Card.Color color = Card.Color.BLUE; //Vorübergehend Blau game.changeLastPlayedCardColor(color); } + // Draw + if (card.getValue() == Card.Value.DRAWTWO) { + nextPlayer(); + drawCard(2); + nextPlayer(); + } } public boolean legalMove(Player player, Card card) From 4ff22f7830e20dcc4f5315d981be762eb2259f13 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 17:21:14 +0100 Subject: [PATCH 10/15] add playCard ChooseDraw --- .../java/de/hsfulda/onses/services/GameService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index bca18b9..92293de 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -46,6 +46,7 @@ public class GameService { // Abfrage Farbe Card.Color color = Card.Color.BLUE; //Vorübergehend Blau game.changeLastPlayedCardColor(color); + nextPlayer(); } // Draw if (card.getValue() == Card.Value.DRAWTWO) { @@ -53,6 +54,15 @@ public class GameService { drawCard(2); nextPlayer(); } + // ChooseDraw + if (card.getValue() == Card.Value.CHOOSEDRAW) { + // Abfrage Farbe + Card.Color color = Card.Color.BLUE; //Vorübergehend Blau + game.changeLastPlayedCardColor(color); + nextPlayer(); + drawCard(4); + nextPlayer(); + } } public boolean legalMove(Player player, Card card) From 6cb972cf78abacec803203b1fdeca3c26e6c2144 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 17:23:14 +0100 Subject: [PATCH 11/15] Test.ChooseDrawTest --- .../java/de/hsfulda/onses/GameServiceTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 5c5fe84..f54dee2 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -227,4 +227,22 @@ public class GameServiceTest { } + @Test + @DisplayName("ChooseDrawTest") + public void ChooseDrawTest () + { + GameService gameservice = new GameService(); + boolean expected = true; + boolean answer = false; + + gameservice.playCard(new Player(), new Card().setValue(Card.Value.CHOOSEDRAW).setColor(Card.Color.BLACK)); + + if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { + answer = true; + } + + assertEquals(expected, answer); + + } + } From 16aff085c0fee024fd1579c25ade8c9cc2e0adab Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 17:36:54 +0100 Subject: [PATCH 12/15] add gameService drawCard --- .../java/de/hsfulda/onses/services/GameService.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 92293de..3f32a14 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -24,7 +24,16 @@ public class GameService { game.getPlayerService().nextTurn(); } public void drawCard(int amount) { - + Player player = null; + if (game.getPlayerService().getCurrentTurn()) { + player = game.getPlayerService().getPlayerList().getFirst(); + } else { + player = game.getPlayerService().getPlayerList().getLast(); + } + for (int i = 0; i < amount; i++) { + player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); + game.getDrawCardDeck().removeFirst(); + } } public void playCard(Player player, Card card) { From a9e53387a2bd6f7a322fa0253688c794674d685f Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 18:16:25 +0100 Subject: [PATCH 13/15] add fillDrawCardDeck to Constuctor --- src/main/java/de/hsfulda/onses/services/GameService.java | 2 ++ src/test/java/de/hsfulda/onses/GameServiceTest.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 3f32a14..3ca661d 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -11,6 +11,8 @@ public class GameService { public GameService(Game game) { this.game = game; this.game.setGameService(this); + fillDrawDeck(); + shuffleDeck(); } public GameService() { this(new Game()); diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index f54dee2..1fb6e98 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -68,7 +68,7 @@ public class GameServiceTest { @DisplayName("FillDrawCardDeck") public void FillDrawCardDeck() { GameService gameService = new GameService(); - int expected = 112; + int expected = gameService.getGame().getDrawCardDeck().size() + 112; gameService.fillDrawDeck(); int answer = gameService.getGame().getDrawCardDeck().size(); From 96370f47c7e31822dfcffc32615b790c94e6ceea Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 18:17:33 +0100 Subject: [PATCH 14/15] Test.DrawCardDeckTest --- .../java/de/hsfulda/onses/GameServiceTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 1fb6e98..1012373 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -245,4 +245,18 @@ public class GameServiceTest { } + @Test + @DisplayName("DrawCardDeckTest") + public void DrawCardDeckTest () + { + GameService gameService = new GameService(); + int before = gameService.getGame().getDrawCardDeck().size(); + gameService.drawCard(4); + int after = gameService.getGame().getDrawCardDeck().size(); + + int expected = 4; + int answer = before - after; + assertEquals(expected, answer); + } + } From e8eeecba90d4c6aea63d4270720eb5573a7706e0 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Fri, 2 Feb 2024 18:18:32 +0100 Subject: [PATCH 15/15] Test.DrawCradDeckRemove --- .../java/de/hsfulda/onses/GameServiceTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 1012373..f6a6eef 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -259,4 +259,22 @@ public class GameServiceTest { assertEquals(expected, answer); } + @Test + @DisplayName("DrawCardDeckRemoveTest") + public void DrawCardDeckRemoveTest () + { + GameService gameService = new GameService(); + Card card = gameService.getGame().getDrawCardDeck().getFirst(); + gameService.drawCard(1); + int counter = 0; + int expected = 0; + for (int i = 0; i < gameService.getGame().getDrawCardDeck().size(); i++) { + if (gameService.getGame().getDrawCardDeck().get(i).getColor() == card.getColor() && gameService.getGame().getDrawCardDeck().get(i).getValue() == card.getValue()) counter++; + } + if (card.getColor() == Card.Color.BLACK) expected = 3; + else expected = 1; + + assertEquals(expected, counter); + } + }