forked from rabinovichr/Project02
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tribe.java
executable file
·148 lines (134 loc) · 4.25 KB
/
Tribe.java
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
package Project02;
import java.util.Collection;
import java.util.Collections;
import java.io.StringBufferInputStream;
import java.util.ArrayList;
/**
* Class is used to create a tribe under a nation that has a certain amount of life points.
*/
public class Tribe
{
private String nationName;
private String tribeName;
private int tribeLifePoints;
private ArrayList<People> members = new ArrayList<>();
private ArrayList<People> livingMembers = new ArrayList<>();
private BuildNationNaveed buildNationNaveed = new BuildNationNaveed();
private BuildNationToyberg buildNationToyberg = new BuildNationToyberg();
private BuildNationSmilons buildSmilons = new BuildNationSmilons();
private BuildNationPerez buildNationPerez = new BuildNationPerez();
private BuildSpecialEncounters buildSpecialEncounters = new BuildSpecialEncounters();
/**
* Create tribes under the given nation using the people types warrior, wizzard, healer.
* Each tribe is given 1/3 of the life points.
* @param lifePoints is the remaining health the tribe has.
* @param nation the given nation name that the tribe will be located under.
* @param tribe the name of the tribe
*/
public Tribe(String nation, String tribe, int lifePoints)
{
nationName = nation;
tribeName = tribe;
tribeLifePoints = lifePoints;
addPlayerstoNation();
for(int i = 0; i < members.size(); i++)
livingMembers.addAll(members);
}
/**
* Checks for each nation and connects to another class that uses an interface
* to add the players for each tribe.
*/
private void addPlayerstoNation()
{
if (this.nationName.equals("Naveed"))
{
buildNationNaveed.add(members,nationName,tribeName,tribeLifePoints);
}
if (this.nationName.equals("Toyberg"))
{
buildNationToyberg.add(members,nationName,tribeName,tribeLifePoints);
}
if(this.nationName.equals("Perez"))
{
buildNationPerez.add(members,nationName,tribeName,tribeLifePoints);
}
if(this.nationName.equals("Smilons"))
{
buildSmilons.add(members,nationName,tribeName,tribeLifePoints);
}
if(this.nationName.equals("Special Scenario"))
{
buildSpecialEncounters.add(members,nationName,tribeName,tribeLifePoints);
}
}
/**
*Gets and returns the number of living tribe members based on the size of
*the members array list. Also keeps track of the tribes current life points.
* @return livingMembers
*/
public ArrayList<People> getLivingTribeMembers()
{
livingMembers.clear();
tribeLifePoints = 0;
for(int person = 0; person < members.size(); person++)
{
if(members.get(person).isPersonAlive())
{
livingMembers.add(members.get(person));
tribeLifePoints += members.get(person).getLifePoints();
//System.out.println(members.get(person));
}
else
{
if(!(members.get(person).getDead()))
{
members.get(person).setDead();
System.out.println("\t\t" + members.get(person) + " is dead!");
}
}
}
return livingMembers;
}
/**
* @return size of the current living members
* */
public int getTribeSize()
{
return livingMembers.size();
}
/**
* @return if tripe is alive
*/
public Boolean isTribeAlive()
{
return (tribeLifePoints > 0);
}
/**
* @return the number of life points remaining
*/
public int getTribeLifePoints()
{
return tribeLifePoints;
}
/**
* @return the name of the given tribe
*/
public String getTribeName()
{
return tribeName;
}
/**
* @return concat the tribe members to the tribe name
*/
public String toString()
{
String result = "\0";
result = tribeName;
for(int i = 0; i < members.size(); i++)
{
result = result + '\n' + members.get(i).toString();
}
result = result + '\n';
return result;
}
}