From d5b3b8236f7cf8a6f3c675da1f38cd01841e35d7 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sat, 3 Feb 2024 00:02:22 +0100 Subject: [PATCH 1/4] refactoring: remove useless variable in legalMove --- .../java/de/hsfulda/onses/services/GameService.java | 2 +- src/test/java/de/hsfulda/onses/GameServiceTest.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 3ca661d..fe77037 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -76,7 +76,7 @@ public class GameService { } } - public boolean legalMove(Player player, Card card) + public boolean legalMove(Card card) { boolean legalMoveFound = false; Card lastCard = game.getLastPlayedCard(); diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index f6a6eef..cf6cf3b 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -46,7 +46,7 @@ public class GameServiceTest { GameService gameService = new GameService(); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); - boolean answer = gameService.legalMove(new Player(), input); + boolean answer = gameService.legalMove(input); // assert assertEquals(expected, answer); } @@ -60,7 +60,7 @@ public class GameServiceTest { GameService gameService = new GameService(); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.ONE)); - boolean answer = gameService.legalMove(new Player(), input); + boolean answer = gameService.legalMove(input); // assert assertEquals(expected, answer); } @@ -86,7 +86,7 @@ public class GameServiceTest { GameService gameService = new GameService(); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.ONE)); - boolean answer = gameService.legalMove(new Player(), input); + boolean answer = gameService.legalMove(input); // assert assertEquals(expected, answer); } @@ -101,7 +101,7 @@ public class GameServiceTest { GameService gameService = new GameService(); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); - boolean answer = gameService.legalMove(new Player(), input); + boolean answer = gameService.legalMove(input); // assert assertEquals(expected, answer); } @@ -116,7 +116,7 @@ public class GameServiceTest { GameService gameService = new GameService(); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); - boolean answer = gameService.legalMove(new Player(), input); + boolean answer = gameService.legalMove(input); // assert assertEquals(expected, answer); } @@ -131,7 +131,7 @@ public class GameServiceTest { GameService gameService = new GameService(); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FIVE)); - boolean answer = gameService.legalMove(new Player(), input); + boolean answer = gameService.legalMove(input); // assert assertEquals(expected, answer); } From 014a7259cce3f2a3f9fa8ffd86d671c50c3b7a9e Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sat, 3 Feb 2024 00:13:00 +0100 Subject: [PATCH 2/4] refactoring: make setCurrentTurn void --- src/main/java/de/hsfulda/onses/services/PlayerService.java | 3 +-- 1 file changed, 1 insertion(+), 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 b3b4cc4..3b32e3a 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -28,9 +28,8 @@ public class PlayerService { return currentTurn; } - public PlayerService setCurrentTurn(boolean currentTurn) { + public void setCurrentTurn(boolean currentTurn) { this.currentTurn = currentTurn; - return this; } public Game getGame() { From 620b82e202139f12fcf9112b6250013f1bc92785 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sat, 3 Feb 2024 00:41:33 +0100 Subject: [PATCH 3/4] refactoring: move one nextTurn into drawCard --- src/main/java/de/hsfulda/onses/services/GameService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index fe77037..92dd8cb 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -36,6 +36,9 @@ public class GameService { player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); game.getDrawCardDeck().removeFirst(); } + if (amount != 1) { + nextPlayer(); + } } public void playCard(Player player, Card card) { @@ -63,7 +66,6 @@ public class GameService { if (card.getValue() == Card.Value.DRAWTWO) { nextPlayer(); drawCard(2); - nextPlayer(); } // ChooseDraw if (card.getValue() == Card.Value.CHOOSEDRAW) { @@ -72,7 +74,6 @@ public class GameService { game.changeLastPlayedCardColor(color); nextPlayer(); drawCard(4); - nextPlayer(); } } From 41e204ca544c56d97bc1b171eb43d053c3c8bfe5 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sat, 3 Feb 2024 00:49:50 +0100 Subject: [PATCH 4/4] refactoring: remove unused Player in playCard --- .../java/de/hsfulda/onses/services/GameService.java | 2 +- src/test/java/de/hsfulda/onses/GameServiceTest.java | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 92dd8cb..2e9424b 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -40,7 +40,7 @@ public class GameService { nextPlayer(); } } - public void playCard(Player player, Card card) + public void playCard(Card card) { // add lastPlayedCard back to drawCardDeck game.setLastPlayedCard(card); diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index cf6cf3b..81ab433 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -1,7 +1,6 @@ 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.*; @@ -18,7 +17,7 @@ public class GameServiceTest { Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.EIGHT); // act GameService gameService = new GameService(); - gameService.playCard(new Player(), input); + gameService.playCard(input); Card answer = gameService.getGame().getLastPlayedCard(); // assert assertEquals(input, answer); @@ -30,7 +29,7 @@ public class GameServiceTest { Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); // act GameService gameService = new GameService(); - gameService.playCard(new Player(), input); + gameService.playCard(input); Card answer = gameService.getGame().getLastPlayedCard(); // assert assertEquals(input, answer); @@ -192,7 +191,7 @@ public class GameServiceTest { GameService gameservice = new GameService(); boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); - gameservice.playCard(new Player(), new Card().setValue(Card.Value.SKIP).setColor(Card.Color.BLACK)); + gameservice.playCard(new Card().setValue(Card.Value.SKIP).setColor(Card.Color.BLACK)); assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); } @@ -204,7 +203,7 @@ public class GameServiceTest { GameService gameservice = new GameService(); boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); - gameservice.playCard(new Player(), new Card().setValue(Card.Value.REVERSE).setColor(Card.Color.BLACK)); + gameservice.playCard(new Card().setValue(Card.Value.REVERSE).setColor(Card.Color.BLACK)); assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); } @@ -217,7 +216,7 @@ public class GameServiceTest { boolean expected = true; boolean answer = false; - gameservice.playCard(new Player(), new Card().setValue(Card.Value.CHOOSE).setColor(Card.Color.BLACK)); + gameservice.playCard(new Card().setValue(Card.Value.CHOOSE).setColor(Card.Color.BLACK)); if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { answer = true; @@ -235,7 +234,7 @@ public class GameServiceTest { boolean expected = true; boolean answer = false; - gameservice.playCard(new Player(), new Card().setValue(Card.Value.CHOOSEDRAW).setColor(Card.Color.BLACK)); + gameservice.playCard(new Card().setValue(Card.Value.CHOOSEDRAW).setColor(Card.Color.BLACK)); if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { answer = true;