PlayerManager.java (1707B) download
1package nl.isygameclient.models;
2
3import java.util.ArrayList;
4import java.util.Objects;
5
6public class PlayerManager {
7 protected int startingPlayerIndex;
8 protected int currentPlayerIndex;
9 protected final ArrayList<Player> players;
10
11 public PlayerManager(int startingPlayerIndex, ArrayList<Player> players) {
12 this.startingPlayerIndex = startingPlayerIndex;
13 this.currentPlayerIndex = startingPlayerIndex;
14 this.players = players;
15 }
16
17 public void restart() {
18 currentPlayerIndex = startingPlayerIndex;
19 }
20
21 public void nextPlayer() {
22 currentPlayerIndex += 1;
23 if (currentPlayerIndex >= players.size()) {
24 currentPlayerIndex = 0;
25 }
26 }
27 public void previousPlayer() {
28 currentPlayerIndex -= 1;
29 if (currentPlayerIndex < 0) {
30 currentPlayerIndex = players.size() - 1;
31 }
32 }
33
34 public boolean isCurrentPlayer(Player player) {
35 return Objects.equals(player, getCurrentPlayer());
36 }
37
38 public Player getCurrentPlayer(){
39 return players.get(currentPlayerIndex);
40 }
41
42 public Player getStartingPlayer() {
43 return players.get(startingPlayerIndex);
44 }
45
46 public ArrayList<Player> getPlayers(){
47 return players;
48 }
49
50 public int getStartingPlayerIndex() {
51 return startingPlayerIndex;
52 }
53
54 public int getCurrentPlayerIndex() {
55 return currentPlayerIndex;
56 }
57
58 public void setStartingPlayerIndex(int startingPlayerIndex) {
59 this.startingPlayerIndex = startingPlayerIndex;
60 }
61
62 public void setCurrentPlayerIndex(int currentPlayerIndex) {
63 this.currentPlayerIndex = currentPlayerIndex;
64 }
65
66
67}