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; diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index c9acd67..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()); @@ -20,11 +22,58 @@ public class GameService { return game; } + public void nextPlayer() { + 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) { // add lastPlayedCard back to drawCardDeck game.setLastPlayedCard(card); // check for special rules (draw, colorchoose, skip,...) + // Skip + if (card.getValue() == Card.Value.SKIP) { + nextPlayer(); + nextPlayer(); + } + // Reverse + if (card.getValue() == Card.Value.REVERSE) { + nextPlayer(); + nextPlayer(); + } + // Choose + if (card.getValue() == Card.Value.CHOOSE) { + // Abfrage Farbe + Card.Color color = Card.Color.BLUE; //Vorübergehend Blau + game.changeLastPlayedCardColor(color); + nextPlayer(); + } + // Draw + if (card.getValue() == Card.Value.DRAWTWO) { + nextPlayer(); + 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) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index c76e1d4..f6a6eef 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(); @@ -185,4 +185,96 @@ 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()); + } + + @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()); + } + + @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); + + } + + @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); + + } + + @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); + } + + @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); + } + }