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