Browse Source

Merge branch 'Refactorings' into 'main'

Refactorings

See merge request fdai7736/onses!18
main
fdai7920 11 months ago
parent
commit
bec2f11f59
  1. 9
      src/main/java/de/hsfulda/onses/services/GameService.java
  2. 3
      src/main/java/de/hsfulda/onses/services/PlayerService.java
  3. 25
      src/test/java/de/hsfulda/onses/GameServiceTest.java

9
src/main/java/de/hsfulda/onses/services/GameService.java

@ -36,8 +36,11 @@ public class GameService {
player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); player.getPlayerDeck().add(game.getDrawCardDeck().getFirst());
game.getDrawCardDeck().removeFirst(); game.getDrawCardDeck().removeFirst();
} }
if (amount != 1) {
nextPlayer();
}
} }
public void playCard(Player player, Card card)
public void playCard(Card card)
{ {
// add lastPlayedCard back to drawCardDeck // add lastPlayedCard back to drawCardDeck
game.setLastPlayedCard(card); game.setLastPlayedCard(card);
@ -63,7 +66,6 @@ public class GameService {
if (card.getValue() == Card.Value.DRAWTWO) { if (card.getValue() == Card.Value.DRAWTWO) {
nextPlayer(); nextPlayer();
drawCard(2); drawCard(2);
nextPlayer();
} }
// ChooseDraw // ChooseDraw
if (card.getValue() == Card.Value.CHOOSEDRAW) { if (card.getValue() == Card.Value.CHOOSEDRAW) {
@ -72,11 +74,10 @@ public class GameService {
game.changeLastPlayedCardColor(color); game.changeLastPlayedCardColor(color);
nextPlayer(); nextPlayer();
drawCard(4); drawCard(4);
nextPlayer();
} }
} }
public boolean legalMove(Player player, Card card)
public boolean legalMove(Card card)
{ {
boolean legalMoveFound = false; boolean legalMoveFound = false;
Card lastCard = game.getLastPlayedCard(); Card lastCard = game.getLastPlayedCard();

3
src/main/java/de/hsfulda/onses/services/PlayerService.java

@ -28,9 +28,8 @@ public class PlayerService {
return currentTurn; return currentTurn;
} }
public PlayerService setCurrentTurn(boolean currentTurn) {
public void setCurrentTurn(boolean currentTurn) {
this.currentTurn = currentTurn; this.currentTurn = currentTurn;
return this;
} }
public Game getGame() { public Game getGame() {

25
src/test/java/de/hsfulda/onses/GameServiceTest.java

@ -1,7 +1,6 @@
package de.hsfulda.onses; package de.hsfulda.onses;
import de.hsfulda.onses.models.Game;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; 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); Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.EIGHT);
// act // act
GameService gameService = new GameService(); GameService gameService = new GameService();
gameService.playCard(new Player(), input);
gameService.playCard(input);
Card answer = gameService.getGame().getLastPlayedCard(); Card answer = gameService.getGame().getLastPlayedCard();
// assert // assert
assertEquals(input, answer); assertEquals(input, answer);
@ -30,7 +29,7 @@ public class GameServiceTest {
Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE);
// act // act
GameService gameService = new GameService(); GameService gameService = new GameService();
gameService.playCard(new Player(), input);
gameService.playCard(input);
Card answer = gameService.getGame().getLastPlayedCard(); Card answer = gameService.getGame().getLastPlayedCard();
// assert // assert
assertEquals(input, answer); assertEquals(input, answer);
@ -46,7 +45,7 @@ public class GameServiceTest {
GameService gameService = new GameService(); GameService gameService = new GameService();
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); 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 // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@ -60,7 +59,7 @@ public class GameServiceTest {
GameService gameService = new GameService(); GameService gameService = new GameService();
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.ONE)); 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 // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@ -86,7 +85,7 @@ public class GameServiceTest {
GameService gameService = new GameService(); GameService gameService = new GameService();
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.ONE)); 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 // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@ -101,7 +100,7 @@ public class GameServiceTest {
GameService gameService = new GameService(); GameService gameService = new GameService();
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); 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 // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@ -116,7 +115,7 @@ public class GameServiceTest {
GameService gameService = new GameService(); GameService gameService = new GameService();
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); 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 // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@ -131,7 +130,7 @@ public class GameServiceTest {
GameService gameService = new GameService(); GameService gameService = new GameService();
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FIVE)); 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 // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@ -192,7 +191,7 @@ public class GameServiceTest {
GameService gameservice = new GameService(); GameService gameservice = new GameService();
boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); 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()); assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn());
} }
@ -204,7 +203,7 @@ public class GameServiceTest {
GameService gameservice = new GameService(); GameService gameservice = new GameService();
boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); 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()); assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn());
} }
@ -217,7 +216,7 @@ public class GameServiceTest {
boolean expected = true; boolean expected = true;
boolean answer = false; 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) { if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) {
answer = true; answer = true;
@ -235,7 +234,7 @@ public class GameServiceTest {
boolean expected = true; boolean expected = true;
boolean answer = false; 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) { if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) {
answer = true; answer = true;

Loading…
Cancel
Save