forked from get-flord/Project2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClanStats.java
More file actions
executable file
·106 lines (95 loc) · 3.21 KB
/
ClanStats.java
File metadata and controls
executable file
·106 lines (95 loc) · 3.21 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
package clanmelee;
/**
* Class to keep track fo the number of clans, hitPoints for each clan, number of players for each clan,
* number of warriors and healers for each clan.
*/
public class ClanStats {
private final int totalClanCount;
private int[] hitPoints;
private int[] playerCounts;
private int[] warriorCounts;
private int[] healerCounts;
/**
* Initializes the length of the Lists of ints to the length of clanCount
* @param clanCount int - number of clans that are involved
*/
public ClanStats(int clanCount) {
this.totalClanCount = clanCount;
this.hitPoints = new int[clanCount];
this.playerCounts = new int[clanCount];
this.warriorCounts = new int[clanCount];
this.healerCounts = new int[clanCount];
}
/**
* Adds a ClanMember to playCounts and healerCounts or warriorCounts
* @param p ClanMember - the clanMember to add to playerCounts and healerORwarriorCounts
*/
public void addPlayer(ClanMember p) {
int clanID = p.getClanID();
hitPoints[clanID] += p.getHitPoints();
playerCounts[clanID] += 1;
if (p.getType() == ClanMember.ClanMemberType.HEALER)
healerCounts[clanID] += 1;
else if (p.getType() == ClanMember.ClanMemberType.WARRIOR)
warriorCounts[clanID] += 1;
}
/**
* Getter method for the number of hit point a specific clan has
* @param clanID int - the ID of the clan desired
* @return int - the number of hit points a clan has
*/
public int getHitPoints(int clanID) {
return hitPoints[clanID];
}
/**
* Getter method for the number of players in a specific clan
* @param clanID int - the ID of the desired clan
* @return int - the number of player in the clan
*/
public int getPlayerCount(int clanID) {
return playerCounts[clanID];
}
/**
* Getter method for the number of warriors in a specific clan
* @param clanID int - the ID of the desired clan
* @return int - the number of warriors in the clan
*/
public int getWarriorCount(int clanID) {
return warriorCounts[clanID];
}
/**
* Getter method for the number of healers in a specific clan
* @param clanID int - the ID of the desired clan
* @return int - the number of healers in the clan
*/
public int getHealerCount(int clanID) {
return healerCounts[clanID];
}
/**
* Getter method for the total number of players involved for all clans
* @return int - all the players involved for all clans
*/
public int getClanCount() {
int clanCount = 0;
for (int i = 0; i < totalClanCount; i++) {
if (playerCounts[i] != 0)
clanCount += 1;
}
return clanCount;
}
/**
* Getter method to return the ID of the clan with the most hit points 'the winner'
* @return int - the ID of the winning clan
*/
public int getWinner() {
int max = 0;
int maxID = 0;
for (int i = 0; i < totalClanCount; i++) {
if (hitPoints[i] > max) {
max = hitPoints[i];
maxID = i;
}
}
return maxID;
}
}