-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTribe.java
More file actions
executable file
·127 lines (113 loc) · 3.33 KB
/
Tribe.java
File metadata and controls
executable file
·127 lines (113 loc) · 3.33 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
package Project01;
import java.util.Collection;
import java.util.Collections;
import java.io.StringBufferInputStream;
import java.util.ArrayList;
import Project01.People;
import Project01.PeopleType;
/**
* 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<>();
/**
* 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;
for(int i = 0; i < 3; i++) {
if (i == 2)
members.add(new People(nationName, tribeName, PeopleType.warrior, tribeLifePoints / 3));
if (i == 1)
members.add(new People(nationName, tribeName, PeopleType.wizzard, tribeLifePoints / 3));
else
members.add(new People(nationName, tribeName, PeopleType.healer, tribeLifePoints / 3));
}
for(int i = 0; i < members.size(); i++)
livingMembers.addAll(members);
}
/**
*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));
}
}
//System.out.println(livingMembers);
return livingMembers;
}
/*
public void printMembers()
{
for(int i = 0; i < 2; i++)
{
System.out.println(people.get(i));
}
}
*/
/**
* @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;
}
}