-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameOver.pde
82 lines (67 loc) · 1.59 KB
/
GameOver.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
public class GameOver extends Transitionable {
// * DRAWING CONSTANTS
public int txt_size = 50;
public static final int txt_h = Snap.ch - 200;
public int p1Scor = 0;
public int p2Scor = 0;
public String winnerName = null;
public boolean alreadyCalculated = false;
public boolean tie = false;
protected void _setup() {
shouldUpdate = false;
}
protected void preUpdate() {
super.preUpdate();
// Calculate the winner
if (m.gOver && !alreadyCalculated) {
calc();
trans = true;
alreadyCalculated = true;
clean();
}
}
protected void _update() {
textAlign(CENTER);
imageMode(CENTER);
if (tie) {
text("GAME TIED", m.cw, m.ch);
} else {
text(winnerName + " WON the game!", m.cw, txt_h);
image(a.king, 500, 700);
}
}
protected void onTransOutBegin() {
paused = true;
shouldUpdate = true;
}
// Calculates the winner for the game
private void calc() {
// Calculate the scores
m.l1.calc();
m.l2.calc();
m.l3.calc();
if (m.l1.p1Scor > m.l1.p2Scor) {
p1Scor++;
} else if (m.l1.p1Scor < m.l1.p2Scor) {
p2Scor++;
}
if (m.l2.p1Scor > m.l2.p2Scor) {
p1Scor++;
} else if (m.l2.p1Scor < m.l2.p2Scor) {
p2Scor++;
}
if (m.l3.p1Scor > m.l3.p2Scor) {
p1Scor++;
} else if (m.l3.p1Scor < m.l3.p2Scor) {
p2Scor++;
}
if (p1Scor > p2Scor) {
winnerName = m.p1.name;
} else if (p2Scor > p1Scor) {
winnerName = m.p2.name;
} else {
tie = true;
}
}
public GameOver(Snap app) { super(app); }
}