Repository navigation
Expand file tree
/
Copy pathPlayerClass
More file actions
80 lines (71 loc) · 1.69 KB
/
Copy pathPlayerClass
File metadata and controls
80 lines (71 loc) · 1.69 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
import java.util.ArrayList;
public class Players
{
private ArrayList<String> alive;
private ArrayList<String> dead;
private String myName;
/**
* Constructor for objects of class Players
*/
public Players()
{
this.alive = new ArrayList<String>();
this.dead = new ArrayList<String>();
this.myName = "";
}
public void setMyName(String str)
{
this.myName = str;
}
public void addPlayer(String str)
{
this.alive.add(str);
}
public void swapPlayer(String str, String swap)
{
if(swap.equals("KILLED"))
{
for(int rep = this.alive.size() -1; rep >= 0; rep--)
{
if(this.alive.get(rep).equals(str))
{
this.alive.remove(rep);
this.dead.add(str);
}
}
}
else
{
for(int rep = this.dead.size() -1; rep >= 0; rep--)
{
if(this.dead.get(rep).equals(str))
{
this.dead.remove(rep);
this.alive.add(str);
}
}
}
}
public String getRandomAlivePlayer()
{
int position = (int) (Math.random()*alive.size());
return alive.get(position);
}
public String getRandomDeadPlayer()
{
int position = (int) (Math.random()*dead.size());
return dead.get(position);
}
public ArrayList<String> getAlive()
{
return this.alive;
}
public ArrayList<String> getDead()
{
return this.dead;
}
public String getMyName()
{
return this.myName;
}
}