From 2281108c54a4509cab1e92cfe69c71c2276f1cd5 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Tue, 30 Jan 2024 15:21:27 +0100 Subject: [PATCH 01/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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 b3e8d49aecad149c0b4af2bb8787c159837d3e6b Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 11:25:49 +0100 Subject: [PATCH 11/14] 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 12/14] 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 13/14] 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 14/14] 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); + } }