From 2281108c54a4509cab1e92cfe69c71c2276f1cd5 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Tue, 30 Jan 2024 15:21:27 +0100 Subject: [PATCH 01/20] add PlayerService --- .../hsfulda/onses/services/PlayerService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/de/hsfulda/onses/services/PlayerService.java diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java new file mode 100644 index 0000000..ee4b864 --- /dev/null +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -0,0 +1,18 @@ +package de.hsfulda.onses.services; + +import de.hsfulda.onses.models.Player; + +import java.util.ArrayList; + +public class PlayerService { + + private final ArrayList playerList = new ArrayList<>(); + + public ArrayList getPlayerList() { + return playerList; + } + public void addPlayerToList(Player player) { + playerList.add(player); + } + +} From f5f22c193170bed8e7d393dcb9a9979b5ab90e56 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Tue, 30 Jan 2024 15:29:12 +0100 Subject: [PATCH 02/20] Test.playerList --- .../de/hsfulda/onses/PlayerServiceTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/java/de/hsfulda/onses/PlayerServiceTest.java diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java new file mode 100644 index 0000000..2ccdb19 --- /dev/null +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -0,0 +1,28 @@ + +package de.hsfulda.onses; + +import de.hsfulda.onses.services.PlayerService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +import de.hsfulda.onses.models.Player; + +public class PlayerServiceTest { + + @Test + @DisplayName("addPlayerToPlayerList") + void addPlayerToPlayerList() + { + //arrange + Player input = new Player(); + Player expected = input; + // act + PlayerService playerservice = new PlayerService(); + playerservice.addPlayerToList(input); + Player answer = playerservice.getPlayerList().getFirst(); + // assert + assertEquals(expected, answer); + } + +} From 549aa37d20d5f73a1559bf033a9e45a25e0de5ac Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Tue, 30 Jan 2024 15:32:37 +0100 Subject: [PATCH 03/20] Test.playerList2Player --- .../de/hsfulda/onses/PlayerServiceTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 2ccdb19..fc77680 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -24,5 +24,25 @@ public class PlayerServiceTest { // assert assertEquals(expected, answer); } + @Test + @DisplayName("addMultiplePlayerToPlayerList") + void addMultiplePlayerToPlayerList() + { + //arrange + Player input1 = new Player(); + Player expected1 = input1; + Player input2 = new Player(); + Player expected2 = input2; + // act + PlayerService playerservice = new PlayerService(); + playerservice.addPlayerToList(input1); + playerservice.addPlayerToList(input2); + + Player answer1 = playerservice.getPlayerList().getFirst(); + Player answer2 = playerservice.getPlayerList().get(1); + // assert + assertEquals(expected1, answer1); + assertEquals(expected2, answer2); + } } From d736b1bc63ad1153d63b5796d0b0d61f200fae33 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Tue, 30 Jan 2024 15:41:26 +0100 Subject: [PATCH 04/20] add addOpponents --- .../java/de/hsfulda/onses/services/PlayerService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index ee4b864..3cde989 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -15,4 +15,13 @@ public class PlayerService { playerList.add(player); } + + // button on gui activates it + public void addOpponents(int amount) { + for (int i=0; i Date: Tue, 30 Jan 2024 15:51:47 +0100 Subject: [PATCH 05/20] Test.addOpponents --- .../java/de/hsfulda/onses/PlayerServiceTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index fc77680..b5c5b3b 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -45,4 +45,19 @@ public class PlayerServiceTest { assertEquals(expected2, answer2); } + @Test + @DisplayName("addPlayerToPlayerList") + void addAmountOfOpponents() + { + //arrange + int input = 3; + int expected = 3; + // act + PlayerService playerservice = new PlayerService(); + playerservice.addOpponents(input); + int answer = playerservice.getPlayerList().size(); + // assert + assertEquals(expected, answer); + } + } From b6e021276f0ad674f02810f6ff4f66f38d8376d2 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Tue, 30 Jan 2024 15:58:27 +0100 Subject: [PATCH 06/20] Refactoring: addOpponent-test more reliable --- src/test/java/de/hsfulda/onses/PlayerServiceTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index b5c5b3b..1e32e55 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -54,8 +54,12 @@ public class PlayerServiceTest { int expected = 3; // act PlayerService playerservice = new PlayerService(); + int before = playerservice.getPlayerList().size(); + playerservice.addOpponents(input); - int answer = playerservice.getPlayerList().size(); + + int after = playerservice.getPlayerList().size(); + int answer = after - before; // assert assertEquals(expected, answer); } From 50e8421ba38741d996ce749f8fd709fd7e6f1c30 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Tue, 30 Jan 2024 16:10:24 +0100 Subject: [PATCH 07/20] add turns --- .../hsfulda/onses/services/PlayerService.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 3cde989..fff2fb6 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -6,6 +6,8 @@ import java.util.ArrayList; public class PlayerService { + private int currentTurn = 0; // 0-3 + private int totalTurns = 0; // 1-4 private final ArrayList playerList = new ArrayList<>(); public ArrayList getPlayerList() { @@ -13,9 +15,9 @@ public class PlayerService { } public void addPlayerToList(Player player) { playerList.add(player); + totalTurns++; } - // button on gui activates it public void addOpponents(int amount) { for (int i=0; i 0 = main Player (skip -> 2x nextTurn()) + // possible: at start of game random int generator from 0-max to decide who starts first + // currentTurn = 2 --> player.getPlayerList(currentTurn) --> Bot 2 (Player 3) + public void nextTurn() + { + if (currentTurn != totalTurns-1) currentTurn++; + else currentTurn = 0; + } + + + + public int getCurrentTurn() { + return currentTurn; + } + + public PlayerService setCurrentTurn(int currentTurn) { + this.currentTurn = currentTurn; + return this; + } + + public int getTotalTurns() { + return totalTurns; + } + + public PlayerService setTotalTurns(int totalTurns) { + this.totalTurns = totalTurns; + return this; + } } From 015d62dd99ea3d237cbb1f4c7de1f625afa66f2b Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Tue, 30 Jan 2024 16:19:35 +0100 Subject: [PATCH 08/20] Refactoring: addOpponents calling addPlayerToList --- src/main/java/de/hsfulda/onses/services/PlayerService.java | 2 +- src/test/java/de/hsfulda/onses/PlayerServiceTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index fff2fb6..ed36463 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -22,7 +22,7 @@ public class PlayerService { public void addOpponents(int amount) { for (int i=0; i Date: Tue, 30 Jan 2024 16:22:33 +0100 Subject: [PATCH 09/20] Test.totalTurns --- .../de/hsfulda/onses/PlayerServiceTest.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 9f7dbab..0fcc5de 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -12,8 +12,7 @@ public class PlayerServiceTest { @Test @DisplayName("addPlayerToPlayerList") - void addPlayerToPlayerList() - { + void addPlayerToPlayerList() { //arrange Player input = new Player(); Player expected = input; @@ -24,10 +23,10 @@ public class PlayerServiceTest { // assert assertEquals(expected, answer); } + @Test @DisplayName("addMultiplePlayerToPlayerList") - void addMultiplePlayerToPlayerList() - { + void addMultiplePlayerToPlayerList() { //arrange Player input1 = new Player(); Player expected1 = input1; @@ -47,8 +46,7 @@ public class PlayerServiceTest { @Test @DisplayName("addAmountOfOpponents") - void addAmountOfOpponents() - { + void addAmountOfOpponents() { //arrange int input = 3; int expected = 3; @@ -64,4 +62,17 @@ public class PlayerServiceTest { assertEquals(expected, answer); } + @Test + @DisplayName("TotalTurnsEqualsAmountPlayers") + void totalTurnsEqualsAmountPlayers() { + // act + PlayerService playerservice = new PlayerService(); + playerservice.addPlayerToList(new Player()); + playerservice.addOpponents(3); + + int expected = playerservice.getPlayerList().size(); + int answer = playerservice.getTotalTurns(); + // assert + assertEquals(expected, answer); + } } From caf0b4425266cc13432fcc1b8520ad4381fbb7f8 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Tue, 30 Jan 2024 16:37:49 +0100 Subject: [PATCH 10/20] Test.currentTurns --- .../de/hsfulda/onses/PlayerServiceTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 0fcc5de..bb1752a 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -75,4 +75,38 @@ public class PlayerServiceTest { // assert assertEquals(expected, answer); } + @Test + @DisplayName("currentTurnsSwitching") + void currentTurnsSwitching4Players() { + // arrange + int expected = 2; + // act + PlayerService playerservice = new PlayerService(); + playerservice.addPlayerToList(new Player()); + playerservice.addOpponents(3); + + for (int i=0; i < expected; i++){ playerservice.nextTurn(); } + + int answer = playerservice.getCurrentTurn(); + // assert + assertEquals(expected, answer); + } + + @Test + @DisplayName("currentTurnsResettingAfterAfterTotalTurns") + void currentTurnsResettingAfterTotalTurns() { + // arrange + int expected = 0; + // act + PlayerService playerservice = new PlayerService(); + playerservice.addPlayerToList(new Player()); + playerservice.addOpponents(3); + int totalTurns = playerservice.getTotalTurns(); + + for (int i=0; i < totalTurns; i++){ playerservice.nextTurn(); } + + int answer = playerservice.getCurrentTurn(); + // assert + assertEquals(expected, answer); + } } From 02d30a8a069da68f9c5499ceea6703033720ff38 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:22:30 +0100 Subject: [PATCH 11/20] add fillDrawDeck --- .../de/hsfulda/onses/services/GameService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index bdee4d5..d1a440d 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -4,6 +4,8 @@ import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; +import java.util.Collections; + public class GameService { private final Game game; public GameService(Game game) { @@ -34,4 +36,20 @@ public class GameService { return legalMoveFound; } + public void fillDrawDeck() { + 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)); + } + } + } + + 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)); + } + } + } From b97fc758605664301f0b1907b83dda61f87f3ada Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:29:04 +0100 Subject: [PATCH 12/20] Test.FillDrawCardDeck --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 8a22108..ec2d8a6 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 de.hsfulda.onses.models.Game; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -63,5 +64,15 @@ public class GameServiceTest { // assert assertEquals(expected, answer); } + @Test + @DisplayName("FillDrawCardDeck") + public void FillDrawCardDeck() { + GameService gameService = new GameService(); + int expected = 112; + + gameService.fillDrawDeck(); + int answer = gameService.getGame().getDrawCardDeck().size(); + assertEquals(expected, answer); + } } From 9e2839db7f3f8f3975a3427e2651db93f28102ab Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:32:40 +0100 Subject: [PATCH 13/20] add shuffleDeck --- src/main/java/de/hsfulda/onses/services/GameService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index d1a440d..d0c36ab 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -52,4 +52,8 @@ public class GameService { } } + public void shuffleDeck() { + Collections.shuffle(game.getDrawCardDeck()); + } + } From 22ca40565c5bb106270fec8ef3a0d1b869159a02 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:34:27 +0100 Subject: [PATCH 14/20] Test.ShuffleDeck --- .../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 ec2d8a6..a95ac91 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -75,4 +75,22 @@ public class GameServiceTest { assertEquals(expected, answer); } + + @Test + @DisplayName("ShuffelDeck") + public void ShuffelDeck() { + GameService shuffled = new GameService(); + GameService notshuffled = new GameService(); + + shuffled.fillDrawDeck(); + notshuffled.fillDrawDeck(); + shuffled.shuffleDeck(); + + for (int i = 0; i < 10; i++) { + if (shuffled.getGame().getDrawCardDeck().get(i).getValue() == notshuffled.getGame().getDrawCardDeck().get(i).getValue() && + shuffled.getGame().getDrawCardDeck().get(i).getColor() == notshuffled.getGame().getDrawCardDeck().get(i).getColor()) { + fail("Deck wurde nicht richtig gemischt"); + } + } + } } From 2c8cc9cf41be5b683c311036987e313af8380ede Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:45:29 +0100 Subject: [PATCH 15/20] refactoring: Improve TestShuffleDeck --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index a95ac91..9910bea 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -86,9 +86,14 @@ public class GameServiceTest { notshuffled.fillDrawDeck(); shuffled.shuffleDeck(); - for (int i = 0; i < 10; i++) { + int counter = 0; + + for (int i = 0; i < 112; i++) { if (shuffled.getGame().getDrawCardDeck().get(i).getValue() == notshuffled.getGame().getDrawCardDeck().get(i).getValue() && shuffled.getGame().getDrawCardDeck().get(i).getColor() == notshuffled.getGame().getDrawCardDeck().get(i).getColor()) { + counter ++; + } + if (counter == 112) { fail("Deck wurde nicht richtig gemischt"); } } From 3f5b2b7d73eeb267ec6b57ddcdc4054e288413e9 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:53:00 +0100 Subject: [PATCH 16/20] refactoring: TestShuffleDeck Improve Safety --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 9910bea..b22147d 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -88,12 +88,12 @@ public class GameServiceTest { int counter = 0; - for (int i = 0; i < 112; i++) { + for (int i = 0; i < notshuffled.getGame().getDrawCardDeck().size(); i++) { if (shuffled.getGame().getDrawCardDeck().get(i).getValue() == notshuffled.getGame().getDrawCardDeck().get(i).getValue() && shuffled.getGame().getDrawCardDeck().get(i).getColor() == notshuffled.getGame().getDrawCardDeck().get(i).getColor()) { counter ++; } - if (counter == 112) { + if (counter == notshuffled.getGame().getDrawCardDeck().size()) { fail("Deck wurde nicht richtig gemischt"); } } From b3e8d49aecad149c0b4af2bb8787c159837d3e6b Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 11:25:49 +0100 Subject: [PATCH 17/20] remove AddOpponents + Tests --- .../hsfulda/onses/services/PlayerService.java | 7 -- .../de/hsfulda/onses/PlayerServiceTest.java | 66 ------------------- 2 files changed, 73 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index ed36463..b9d0123 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -18,13 +18,6 @@ public class PlayerService { totalTurns++; } - // button on gui activates it - public void addOpponents(int amount) { - for (int i=0; i 0 = main Player (skip -> 2x nextTurn()) // possible: at start of game random int generator from 0-max to decide who starts first diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index bb1752a..02547bb 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -43,70 +43,4 @@ public class PlayerServiceTest { assertEquals(expected1, answer1); assertEquals(expected2, answer2); } - - @Test - @DisplayName("addAmountOfOpponents") - void addAmountOfOpponents() { - //arrange - int input = 3; - int expected = 3; - // act - PlayerService playerservice = new PlayerService(); - int before = playerservice.getPlayerList().size(); - - playerservice.addOpponents(input); - - int after = playerservice.getPlayerList().size(); - int answer = after - before; - // assert - assertEquals(expected, answer); - } - - @Test - @DisplayName("TotalTurnsEqualsAmountPlayers") - void totalTurnsEqualsAmountPlayers() { - // act - PlayerService playerservice = new PlayerService(); - playerservice.addPlayerToList(new Player()); - playerservice.addOpponents(3); - - int expected = playerservice.getPlayerList().size(); - int answer = playerservice.getTotalTurns(); - // assert - assertEquals(expected, answer); - } - @Test - @DisplayName("currentTurnsSwitching") - void currentTurnsSwitching4Players() { - // arrange - int expected = 2; - // act - PlayerService playerservice = new PlayerService(); - playerservice.addPlayerToList(new Player()); - playerservice.addOpponents(3); - - for (int i=0; i < expected; i++){ playerservice.nextTurn(); } - - int answer = playerservice.getCurrentTurn(); - // assert - assertEquals(expected, answer); - } - - @Test - @DisplayName("currentTurnsResettingAfterAfterTotalTurns") - void currentTurnsResettingAfterTotalTurns() { - // arrange - int expected = 0; - // act - PlayerService playerservice = new PlayerService(); - playerservice.addPlayerToList(new Player()); - playerservice.addOpponents(3); - int totalTurns = playerservice.getTotalTurns(); - - for (int i=0; i < totalTurns; i++){ playerservice.nextTurn(); } - - int answer = playerservice.getCurrentTurn(); - // assert - assertEquals(expected, answer); - } } From c376d8f34507a55cac76bf3a41fa39c7bfb04456 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 11:31:07 +0100 Subject: [PATCH 18/20] refactoring: currentTurn to boolean 2PlayerChange --- .../de/hsfulda/onses/services/PlayerService.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index b9d0123..ff9f869 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -6,8 +6,8 @@ import java.util.ArrayList; public class PlayerService { - private int currentTurn = 0; // 0-3 - private int totalTurns = 0; // 1-4 + private boolean currentTurn = true; // true --> real player, false --> Bot + private int totalTurns = 0; private final ArrayList playerList = new ArrayList<>(); public ArrayList getPlayerList() { @@ -19,22 +19,18 @@ public class PlayerService { } - // decides which Player is currently at their turn -> 0 = main Player (skip -> 2x nextTurn()) - // possible: at start of game random int generator from 0-max to decide who starts first - // currentTurn = 2 --> player.getPlayerList(currentTurn) --> Bot 2 (Player 3) public void nextTurn() { - if (currentTurn != totalTurns-1) currentTurn++; - else currentTurn = 0; + currentTurn = !currentTurn; } - public int getCurrentTurn() { + public boolean getCurrentTurn() { return currentTurn; } - public PlayerService setCurrentTurn(int currentTurn) { + public PlayerService setCurrentTurn(boolean currentTurn) { this.currentTurn = currentTurn; return this; } From 6be9ba627edbd1f7f0cc3c929663d2b89f67815a Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 11:33:12 +0100 Subject: [PATCH 19/20] refactoring: remove useless totalTurns 2PlayerChange --- .../de/hsfulda/onses/services/PlayerService.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index ff9f869..d726af8 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -7,7 +7,7 @@ import java.util.ArrayList; public class PlayerService { private boolean currentTurn = true; // true --> real player, false --> Bot - private int totalTurns = 0; + private final ArrayList playerList = new ArrayList<>(); public ArrayList getPlayerList() { @@ -15,17 +15,13 @@ public class PlayerService { } public void addPlayerToList(Player player) { playerList.add(player); - totalTurns++; } - public void nextTurn() { currentTurn = !currentTurn; } - - public boolean getCurrentTurn() { return currentTurn; } @@ -35,12 +31,4 @@ public class PlayerService { return this; } - public int getTotalTurns() { - return totalTurns; - } - - public PlayerService setTotalTurns(int totalTurns) { - this.totalTurns = totalTurns; - return this; - } } From 98ca34b8317fe39bfdc65657fd9b82bc1ad57e98 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 11:43:16 +0100 Subject: [PATCH 20/20] Test.newCurrentTurn --- .../de/hsfulda/onses/PlayerServiceTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 02547bb..08630c6 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -43,4 +43,31 @@ public class PlayerServiceTest { assertEquals(expected1, answer1); assertEquals(expected2, answer2); } + @Test + @DisplayName("checkCurrentTurnAfterNextTurn") + void checkCurrentTurnAfterNextTurn() { + //arrange + boolean expected = true; + // act + PlayerService playerservice = new PlayerService(); + playerservice.setCurrentTurn(false); + playerservice.nextTurn(); + boolean answer = playerservice.getCurrentTurn(); + // assert + assertEquals(expected, answer); + } + @Test + @DisplayName("checkCurrentTurnAfterTwoTurns") + void checkCurrentTurnAfterTwoTurns() { + //arrange + boolean expected = false; + // act + PlayerService playerservice = new PlayerService(); + playerservice.setCurrentTurn(false); + playerservice.nextTurn(); + playerservice.nextTurn(); + boolean answer = playerservice.getCurrentTurn(); + // assert + assertEquals(expected, answer); + } }