diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index e0a9b23..9dbfa14 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -12,6 +12,9 @@ public class Player { private PlayerService playerService; private Game game; + private String playerName; + private boolean enemy; + private Card currentCard; private final ArrayList playerDeck = new ArrayList<>(); public ArrayList getPlayerDeck() { @@ -48,6 +51,33 @@ public class Player { return this; } + public String getPlayerName() { + return playerName; + } + + public Player setPlayerName(String playerName) { + this.playerName = playerName; + return this; + } + + public boolean isEnemy() { + return enemy; + } + + public Player setEnemy(boolean enemy) { + this.enemy = enemy; + return this; + } + + public Card getCurrentCard() { + return currentCard; + } + + public Player setCurrentCard(Card currentCard) { + this.currentCard = currentCard; + return this; + } + public PropertyChangeSupport listeners() { if(this.listeners == null) { this.listeners = new PropertyChangeSupport(this); diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 129790f..6176f7c 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -4,6 +4,7 @@ import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; +import java.util.ArrayList; import java.util.Collections; import java.util.Random; @@ -23,6 +24,7 @@ public class GameService { public GameService(Game game) { this.game = game; this.game.setGameService(this); + this.game.getPlayerService().getPlayerList().getLast().setEnemy(true); fillDrawDeck(); shuffleDeck(); setFirstCard(); @@ -107,6 +109,21 @@ public class GameService { } } + public void playSeven() { + ArrayList übergangBot = new ArrayList<>(game.getPlayerService().getPlayerList().getLast().getPlayerDeck()); + ArrayList übergangSpieler = new ArrayList<>(game.getPlayerService().getPlayerList().getFirst().getPlayerDeck()); + + game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().clear(); + for (int i = 0; i < übergangBot.size(); i++) { + game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().add(übergangBot.get(i)); + } + + game.getPlayerService().getPlayerList().getLast().getPlayerDeck().clear(); + for (int i = 0; i < übergangSpieler.size(); i++) { + game.getPlayerService().getPlayerList().getLast().getPlayerDeck().add(übergangSpieler.get(i)); + } + } + public void checkForWin() { if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty() || this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { this.game.setGameOver(true); diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index de47a5e..0e02461 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 com.sun.jdi.ArrayReference; import de.hsfulda.onses.models.Game; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,6 +12,8 @@ import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Player; import de.hsfulda.onses.services.GameService; +import java.util.ArrayList; + public class GameServiceTest { @Test @DisplayName("playCardRedEight") @@ -474,4 +477,33 @@ public class GameServiceTest { assertTrue(answer); } + + @Test + @DisplayName("PlaySevenPlayerDeckIsNowBotDeck") + public void PlaySevenPlayerDeckIsNowBotDeck() { + GameService gameService = new GameService(); + ArrayList botDeck = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck()); + gameService.playSeven(); + ArrayList answer = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck()); + assertEquals(botDeck, answer); + } + + @Test + @DisplayName("PlaySevenBotDeckIsNowPlayerDeck") + public void PlaySevenBotDeckIsNowPlayerDeck() { + GameService gameService = new GameService(); + ArrayList playerDeck = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck()); + gameService.playSeven(); + ArrayList answer = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck()); + assertEquals(playerDeck, answer); + } + + @Test + @DisplayName("BotisEnemy") + public void botIsEnemy() { + GameService gameService = new GameService(); + boolean answer = gameService.getGame().getPlayerService().getPlayerList().getLast().isEnemy(); + boolean expected = true; + assertEquals(expected, answer); + } } diff --git a/src/test/java/de/hsfulda/onses/PlayerTest.java b/src/test/java/de/hsfulda/onses/PlayerTest.java index 9b68f36..9ce04fd 100644 --- a/src/test/java/de/hsfulda/onses/PlayerTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerTest.java @@ -75,4 +75,43 @@ public class PlayerTest { assertEquals(1, player.getPlayerDeck().size()); assertEquals(card2, player.getPlayerDeck().getFirst()); } + + @Test + @DisplayName("GivePlayerName") + public void GivePlayerName() { + Player player = new Player(); + String expected = "Spieler"; + player.setPlayerName(expected); + String answer = player.getPlayerName(); + assertEquals(expected, answer); + } + + @Test + @DisplayName("ChangePlayerName") + public void ChangePlayerName() { + PlayerService playerService = new PlayerService(); + String name1 = "Name1"; + String name2 = "Name2"; + playerService.getPlayerList().getFirst().setPlayerName(name1); + playerService.getPlayerList().getFirst().setPlayerName(name2); + String answer = playerService.getPlayerList().getFirst().getPlayerName(); + assertEquals(name2, answer); + } + + @Test + @DisplayName("BotIsEnemy") + public void BotIsEnemy() { + Player player = new Player(); + player.setEnemy(true); + assertTrue(player.isEnemy()); + } + + @Test + @DisplayName("CurrentCard") + public void CurrentCard() { + Player player = new Player(); + Card card = new Card().setValue(Card.Value.ONE).setColor(Card.Color.GREEN); + player.setCurrentCard(card); + assertEquals(card, player.getCurrentCard()); + } }