diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 3b32e3a..1d74ef9 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -2,6 +2,7 @@ package de.hsfulda.onses.services; import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; +import de.hsfulda.onses.models.Card; import java.util.ArrayList; @@ -15,12 +16,12 @@ public class PlayerService { public ArrayList getPlayerList() { return playerList; } + public void addPlayerToList(Player player) { playerList.add(player); } - public void nextTurn() - { + public void nextTurn() { currentTurn = !currentTurn; } @@ -43,9 +44,29 @@ public class PlayerService { return this; } - public PlayerService() - { + public PlayerService() { addPlayerToList(new Player().setPlayerService(this)); addPlayerToList(new Player().setPlayerService(this)); } + + public void removeCardFromPlayerDeck(Card card) { + Player player; + if (this.currentTurn) { + player = playerList.getFirst(); + for (int i = 0; i < player.getPlayerDeck().size(); i++) { + if (player.getPlayerDeck().get(i) == card) { + player.getPlayerDeck().remove(i); + break; + } + } + } else { + player = playerList.getLast(); + for (int i = 0; i < player.getPlayerDeck().size(); i++) { + if (player.getPlayerDeck().get(i) == card) { + player.getPlayerDeck().remove(i); + break; + } + } + } + } }