diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index d0c36ab..df7cf87 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -33,6 +33,10 @@ public class GameService { // rules: if (card.getColor() == lastCard.getColor()) legalMoveFound = true; // same color + if (card.getValue() == lastCard.getValue()) legalMoveFound = true; // same value + + if (card.getColor() == Card.Color.BLACK) legalMoveFound = true; // Color Black + return legalMoveFound; } diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index b22147d..7be6f27 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -76,6 +76,65 @@ public class GameServiceTest { assertEquals(expected, answer); } + @Test + @DisplayName("legalMoveSameValueOne") + public void legalMoveSameValueOne() { + // arrange + Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); + boolean expected = true; + // act + GameService gameService = new GameService(); + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.ONE)); + + boolean answer = gameService.legalMove(new Player(), input); + // assert + assertEquals(expected, answer); + } + + @Test + @DisplayName("legalMoveSameValueThree") + public void legalMoveSameValueThree() { + // arrange + Card input = new Card().setColor(Card.Color.GREEN).setValue(Card.Value.THREE); + boolean expected = true; + // act + GameService gameService = new GameService(); + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); + + boolean answer = gameService.legalMove(new Player(), input); + // assert + assertEquals(expected, answer); + } + + @Test + @DisplayName("legalMoveColorBlack") + public void legalMoveColorBlack() { + // arrange + Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); + boolean expected = true; + // act + GameService gameService = new GameService(); + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); + + boolean answer = gameService.legalMove(new Player(), input); + // assert + assertEquals(expected, answer); + } + + @Test + @DisplayName("legalMoveColorBlackCHOOSEDRAW") + public void legalMoveColorBlackCHOOSEDRAW() { + // arrange + Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSEDRAW); + boolean expected = true; + // act + GameService gameService = new GameService(); + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FIVE)); + + boolean answer = gameService.legalMove(new Player(), input); + // assert + assertEquals(expected, answer); + } @Test @DisplayName("ShuffelDeck") public void ShuffelDeck() {