-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayers.java
More file actions
164 lines (141 loc) · 4.17 KB
/
Copy pathPlayers.java
File metadata and controls
164 lines (141 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
/**
* A players class that represents an arraylist of players
*
* @Team MAGA
* @Author Gajun Young - 16440714
* @Author Royal Thomas - 16326926
* @Author Richard Otroshchenko - 16353416
*/
public class Players implements Iterable<Player>, Iterator<Player> {
private static final int DEFAULT_CAPACITY = 6; //Maximum amount of players
private int capacity; //Number of players in the game
private final ArrayList<Player> players;
private Iterator<Player> iterator;
private TileGrid grid = new TileGrid(); //Grid to set players on locations
//Default constructor
public Players() {
players = new ArrayList<Player>(DEFAULT_CAPACITY);
}
//Constructor
public Players(int capacity) {
this.capacity = capacity;
players = new ArrayList<Player>(capacity);
}
//Creating a list of players [Fixed starting location]
public void createPlayers(String name, int choice) {
players.add(new Player(name, choice));
}
//Create tokens for players
public void createTokens(int curr) {
int choice = players.get(curr).getChoice();
switch(choice) {
case 1: //PLUM
players.get(curr).setToken(new Token("Plum", Color.magenta, grid.map[19][23]));
players.get(curr).setImagePath("Profiler/Plum.png");
break;
case 2: //WHITE
players.get(curr).setToken(new Token("White", Color.white, grid.map[0][9]));
players.get(curr).setImagePath("Profiler/White.png");
break;
case 3: //SCARLET
players.get(curr).setToken(new Token("Scarlet", Color.red, grid.map[24][7]));
players.get(curr).setImagePath("Profiler/Scarlet.png");
break;
case 4: //GREEN
players.get(curr).setToken(new Token("Green", Color.green, grid.map[0][14]));
players.get(curr).setImagePath("Profiler/Green.png");
break;
case 5: //MUSTARD
players.get(curr).setToken(new Token("Mustard", Color.yellow, grid.map[17][0]));
players.get(curr).setImagePath("Profiler/Mustard.png");
break;
case 6: //PEACOCK
players.get(curr).setToken(new Token("Peacock", Color.blue, grid.map[6][23]));
players.get(curr).setImagePath("Profiler/Peacock.png");
break;
default:
break;
}
}
//Check if array has the token name
public boolean hasTokenName(String name) {
for(Player Player: players) {
if(Player.getToken().hasName(name)) {
return true;
}
}
return false;
}
//Iterates to check if two tokens are on the same tile
public boolean getSameTile(Tile tile) {
for(Player player: players) {
if(player.hasTile(tile)) {
return true;
}
}
return false;
}
//Return player with the token
public Player getPlayer(String token) {
for(Player player: players) {
if(player.getToken().hasName(token)) {
return player;
}
}
return null;
}
//Iterates to get a specific Player
public Player getName(String name) {
for (Player Player : players) {
if (Player.hasName(name)) {
return Player;
}
}
return null;
}
//Gets the number of people in the array list
public int getCapacity() {
return capacity;
}
//Returns the player at the index
public Player getPlayer(int index) {
return players.get(index);
}
//Returns the Tile of the token/player
public Tile getTile(int index) {
return players.get(index).getToken().getPosition();
}
//Returns the token of the player.
public String getTokenName(int index) {
return players.get(index).getToken().getTokenName();
}
//Remove a player from the array
public void remove(int index) {
players.remove(index);
}
//Start of string containing the player token and the player's name
public String currPlayer(int index) {
return players.get(index).getName() + " [" + players.get(index).getToken().getTokenName() + "] ";
}
//Add Player to the start of the array, move everyone else back in array
public void addFirst(int index, Player temp) {
players.remove(index);
players.add(0, temp);
}
@Override
public Iterator<Player> iterator() {
iterator = players.iterator();
return iterator;
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public Player next() {
return iterator.next();
}
}