diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index ca49d7c..df7cf87 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) { @@ -38,4 +40,24 @@ 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)); + } + } + + public void shuffleDeck() { + Collections.shuffle(game.getDrawCardDeck()); + } + } 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..d726af8 --- /dev/null +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -0,0 +1,34 @@ +package de.hsfulda.onses.services; + +import de.hsfulda.onses.models.Player; + +import java.util.ArrayList; + +public class PlayerService { + + private boolean currentTurn = true; // true --> real player, false --> Bot + + private final ArrayList playerList = new ArrayList<>(); + + public ArrayList getPlayerList() { + return playerList; + } + public void addPlayerToList(Player player) { + playerList.add(player); + } + + public void nextTurn() + { + currentTurn = !currentTurn; + } + + public boolean getCurrentTurn() { + return currentTurn; + } + + public PlayerService setCurrentTurn(boolean currentTurn) { + this.currentTurn = currentTurn; + return this; + } + +} diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 7397d79..7be6f27 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,6 +64,17 @@ 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); + } @Test @DisplayName("legalMoveSameValueOne") @@ -123,5 +135,26 @@ public class GameServiceTest { // assert assertEquals(expected, answer); } - + @Test + @DisplayName("ShuffelDeck") + public void ShuffelDeck() { + GameService shuffled = new GameService(); + GameService notshuffled = new GameService(); + + shuffled.fillDrawDeck(); + notshuffled.fillDrawDeck(); + shuffled.shuffleDeck(); + + int counter = 0; + + 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 == notshuffled.getGame().getDrawCardDeck().size()) { + fail("Deck wurde nicht richtig gemischt"); + } + } + } } 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..08630c6 --- /dev/null +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -0,0 +1,73 @@ + +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); + } + + @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); + } + @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); + } +}