From bcaf4c8aac3cbfb7414bfc578ed4e04e065999be Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 12:58:38 +0100 Subject: [PATCH 01/12] add special Rule playSeven --- .../de/hsfulda/onses/services/GameService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 129790f..29c01d5 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -4,6 +4,7 @@ import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; +import java.util.ArrayList; import java.util.Collections; import java.util.Random; @@ -107,6 +108,21 @@ public class GameService { } } + public void playSeven() { + ArrayList übergangBot = new ArrayList<>(game.getPlayerService().getPlayerList().getLast().getPlayerDeck()); + ArrayList übergangSpieler = new ArrayList<>(game.getPlayerService().getPlayerList().getFirst().getPlayerDeck()); + + game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().clear(); + for (int i = 0; i < übergangBot.size(); i++) { + game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().add(übergangBot.get(i)); + } + + game.getPlayerService().getPlayerList().getLast().getPlayerDeck().clear(); + for (int i = 0; i < übergangSpieler.size(); i++) { + game.getPlayerService().getPlayerList().getLast().getPlayerDeck().add(übergangSpieler.get(i)); + } + } + public void checkForWin() { if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty() || this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { this.game.setGameOver(true); From d2f874a221ed0425f29ecaa1de2a1382328741fb Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 12:59:19 +0100 Subject: [PATCH 02/12] Test.PlaySevenPlayerDeck --- 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 de47a5e..100ebff 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -1,6 +1,7 @@ package de.hsfulda.onses; +import com.sun.jdi.ArrayReference; import de.hsfulda.onses.models.Game; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,6 +12,8 @@ import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Player; import de.hsfulda.onses.services.GameService; +import java.util.ArrayList; + public class GameServiceTest { @Test @DisplayName("playCardRedEight") @@ -474,4 +477,14 @@ public class GameServiceTest { assertTrue(answer); } + + @Test + @DisplayName("PlaySevenPlayerDeckIsNowBotDeck") + public void PlaySevenPlayerDeckIsNowBotDeck() { + GameService gameService = new GameService(); + ArrayList botDeck = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck()); + gameService.playSeven(); + ArrayList answer = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck()); + assertEquals(botDeck, answer); + } } From 399a43075f1b66463f8378c7ef00aee381648e0e Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 13:02:17 +0100 Subject: [PATCH 03/12] Test.PlaySevenBotDeck --- 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 100ebff..617a523 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -487,4 +487,14 @@ public class GameServiceTest { ArrayList answer = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck()); assertEquals(botDeck, answer); } + + @Test + @DisplayName("PlaySevenBotDeckIsNowPlayerDeck") + public void PlaySevenBotDeckIsNowPlayerDeck() { + GameService gameService = new GameService(); + ArrayList playerDeck = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck()); + gameService.playSeven(); + ArrayList answer = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck()); + assertEquals(playerDeck, answer); + } } From b550626bca9bbb34ee1e434f868db8f41f389188 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 15:58:16 +0100 Subject: [PATCH 04/12] add playerName --- src/main/java/de/hsfulda/onses/models/Player.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 09696bd..8e69d6e 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -12,6 +12,7 @@ public class Player { private PlayerService playerService; private Game game; + private String playerName; private final ArrayList playerDeck = new ArrayList<>(); public ArrayList getPlayerDeck() { @@ -42,6 +43,15 @@ public class Player { return this; } + public String getPlayerName() { + return playerName; + } + + public Player setPlayerName(String playerName) { + this.playerName = playerName; + return this; + } + public PropertyChangeSupport listeners() { if(this.listeners == null) { this.listeners = new PropertyChangeSupport(this); From d2b1c0eefb417ea8f88e2a8e6a112298f5904091 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 16:08:58 +0100 Subject: [PATCH 05/12] Test.GivePlayerName --- src/test/java/de/hsfulda/onses/PlayerTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerTest.java b/src/test/java/de/hsfulda/onses/PlayerTest.java index fcdeeac..a803321 100644 --- a/src/test/java/de/hsfulda/onses/PlayerTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerTest.java @@ -58,4 +58,14 @@ public class PlayerTest { assertEquals(expected, answer1); assertEquals(expected, answer2); } + + @Test + @DisplayName("GivePlayerName") + public void getPlayerName() { + Player player = new Player(); + String expected = "Spieler"; + player.setPlayerName(expected); + String answer = player.getPlayerName(); + assertEquals(expected, answer); + } } From 08a17dfea823e66681860b5f6ee1386513062e4d Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 16:09:40 +0100 Subject: [PATCH 06/12] Test.ChangePlayerName --- src/test/java/de/hsfulda/onses/PlayerTest.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/hsfulda/onses/PlayerTest.java b/src/test/java/de/hsfulda/onses/PlayerTest.java index a803321..48b59c9 100644 --- a/src/test/java/de/hsfulda/onses/PlayerTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerTest.java @@ -61,11 +61,23 @@ public class PlayerTest { @Test @DisplayName("GivePlayerName") - public void getPlayerName() { + public void GivePlayerName() { Player player = new Player(); String expected = "Spieler"; player.setPlayerName(expected); String answer = player.getPlayerName(); assertEquals(expected, answer); } + + @Test + @DisplayName("ChangePlayerName") + public void ChangePlayerName() { + PlayerService playerService = new PlayerService(); + String name1 = "Name1"; + String name2 = "Name2"; + playerService.getPlayerList().getFirst().setPlayerName(name1); + playerService.getPlayerList().getFirst().setPlayerName(name2); + String answer = playerService.getPlayerList().getFirst().getPlayerName(); + assertEquals(name2, answer); + } } From fbe6ed036b1aa5b20617744d4e300167246a673b Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 16:31:58 +0100 Subject: [PATCH 07/12] add boolean enemy to player --- src/main/java/de/hsfulda/onses/models/Player.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 8e69d6e..2530bdd 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -13,6 +13,7 @@ public class Player { private PlayerService playerService; private Game game; private String playerName; + private boolean enemy; private final ArrayList playerDeck = new ArrayList<>(); public ArrayList getPlayerDeck() { @@ -52,6 +53,15 @@ public class Player { return this; } + public boolean isEnemy() { + return enemy; + } + + public Player setEnemy(boolean enemy) { + this.enemy = enemy; + return this; + } + public PropertyChangeSupport listeners() { if(this.listeners == null) { this.listeners = new PropertyChangeSupport(this); From 1d85b32fb85877e765a98cba770b4f00428e504c Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 16:33:13 +0100 Subject: [PATCH 08/12] add botIsEnemy in Constructor --- src/main/java/de/hsfulda/onses/services/GameService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 29c01d5..6176f7c 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -24,6 +24,7 @@ public class GameService { public GameService(Game game) { this.game = game; this.game.setGameService(this); + this.game.getPlayerService().getPlayerList().getLast().setEnemy(true); fillDrawDeck(); shuffleDeck(); setFirstCard(); From 0649d639906897503d249d6c1c8a3365e5d07a49 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 16:35:20 +0100 Subject: [PATCH 09/12] Test.BotisEnemy getter setter --- src/test/java/de/hsfulda/onses/PlayerTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerTest.java b/src/test/java/de/hsfulda/onses/PlayerTest.java index 48b59c9..8f99ad7 100644 --- a/src/test/java/de/hsfulda/onses/PlayerTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerTest.java @@ -80,4 +80,12 @@ public class PlayerTest { String answer = playerService.getPlayerList().getFirst().getPlayerName(); assertEquals(name2, answer); } + + @Test + @DisplayName("BotIsEnemy") + public void BotIsEnemy() { + Player player = new Player(); + player.setEnemy(true); + assertTrue(player.isEnemy()); + } } From a8805f66706223696c76409d963f7f4f847db3f5 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 16:36:04 +0100 Subject: [PATCH 10/12] Test.BotisEnemy Constructor --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 617a523..0e02461 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -497,4 +497,13 @@ public class GameServiceTest { ArrayList answer = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck()); assertEquals(playerDeck, answer); } + + @Test + @DisplayName("BotisEnemy") + public void botIsEnemy() { + GameService gameService = new GameService(); + boolean answer = gameService.getGame().getPlayerService().getPlayerList().getLast().isEnemy(); + boolean expected = true; + assertEquals(expected, answer); + } } From f6df79c2258c1619636e331893ea2a7c570a5544 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 16:44:19 +0100 Subject: [PATCH 11/12] add Player CurrentCard --- src/main/java/de/hsfulda/onses/models/Player.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 2530bdd..695e3d4 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -14,6 +14,7 @@ public class Player { private Game game; private String playerName; private boolean enemy; + private Card currentCard; private final ArrayList playerDeck = new ArrayList<>(); public ArrayList getPlayerDeck() { @@ -62,6 +63,15 @@ public class Player { return this; } + public Card getCurrentCard() { + return currentCard; + } + + public Player setCurrentCard(Card currentCard) { + this.currentCard = currentCard; + return this; + } + public PropertyChangeSupport listeners() { if(this.listeners == null) { this.listeners = new PropertyChangeSupport(this); From d1c5543676dc2ebb984d7b2cc1aa570bf25dd308 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 7 Feb 2024 16:45:02 +0100 Subject: [PATCH 12/12] Test.CurrentCard --- src/test/java/de/hsfulda/onses/PlayerTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerTest.java b/src/test/java/de/hsfulda/onses/PlayerTest.java index 8f99ad7..f89e280 100644 --- a/src/test/java/de/hsfulda/onses/PlayerTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerTest.java @@ -88,4 +88,12 @@ public class PlayerTest { player.setEnemy(true); assertTrue(player.isEnemy()); } + @Test + @DisplayName("CurrentCard") + public void CurrentCard() { + Player player = new Player(); + Card card = new Card().setValue(Card.Value.ONE).setColor(Card.Color.GREEN); + player.setCurrentCard(card); + assertEquals(card, player.getCurrentCard()); + } }