-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVotes.pde
68 lines (55 loc) · 1.76 KB
/
Votes.pde
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
enum Verdict {
GUILTY, INNOCENT, NOMINATION
}
/*
Keeps a track of all of the votes made by a player in a given day.
*/
class Votes extends ArrayList<Vote> {
JSONArray toJSON() {
JSONArray retVotes = new JSONArray();
for (int i = 0; i < this.size(); i++)
retVotes.setJSONObject(i, this.get(i).toJSON());
return retVotes;
}
}
class Vote {
Player voter;
Player against;
Verdict decision;
String decisionString;
Vote() {}
Vote(Player voter, Player against, Verdict decision) {
this.voter = voter;
this.against = against;
this.decision = decision;
}
void change(Player against, Verdict decision) {
this.against = against;
this.decision = decision;
}
boolean isGuilty() {
return this.decision == Verdict.GUILTY;
}
boolean isNomination() {
return this.decision == Verdict.NOMINATION;
}
Player getDefendant() {
return against;
}
JSONObject toJSON() {
JSONObject retJSON = new JSONObject();
retJSON.setString("voter", voter.getName());
retJSON.setString("against", against.getName());
retJSON.setString("decision", decision.name());
return retJSON;
}
Vote fromJSON(String source) {
Vote retVote = new Vote();
JSONObject voteJSON = parseJSONObject(source);
retVote.voter = myGame.getPlayerMap().get(voteJSON.getString("voter"));
retVote.against = myGame.getPlayerMap().get(voteJSON.getString("against"));
retVote.decisionString = voteJSON.getString("decision");
retVote.decision = Verdict.valueOf(retVote.decisionString);
return retVote;
}
}