diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 09696bd..695e3d4 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() { @@ -42,6 +45,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 fcdeeac..f89e280 100644 --- a/src/test/java/de/hsfulda/onses/PlayerTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerTest.java @@ -58,4 +58,42 @@ public class PlayerTest { assertEquals(expected, answer1); assertEquals(expected, answer2); } + + @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()); + } }