-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardGame.pde
144 lines (114 loc) · 2.44 KB
/
CardGame.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
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
import java.util.*;
import java.lang.reflect.Field;
import processing.sound.*;
// * Util classes
Assets a = new Assets();
Variables v = new Variables();
TransitionIn transitionIn = new TransitionIn(a, v);
TransitionOut transitionOut = new TransitionOut(a, v);
// * Game classes
Deck deck = new Deck(a, v);
Player player = new Player(a, v);
Enemy enemy = new Enemy(a, v);
Table table = new Table(a, v);
ScoreBar scoreBar = new ScoreBar(a, v);
GameTrans gameTrans = new GameTrans(a, v);
Intro intro = new Intro(a, v);
LowBtn lowBtn = new LowBtn(a, v);
HighBtn highBtn = new HighBtn(a, v);
void setup() {
size(1000, 1000);
background(255);
shapeMode(CENTER);
textAlign(CENTER);
imageMode(CENTER);
noStroke();
// Default fill color is black
fill(0);
a._setup(this);
v._setup();
// * SETUP CLASSES
player.setup();
deck.setup();
enemy.setup();
lowBtn.setup();
highBtn.setup();
// * DEBUGGING INFO
deck.hardDeal(player);
}
void draw() {
background(255);
if (intro.show) {
intro.update();
return;
}
checkBtns();
table.update();
scoreBar.update();
player.update();
deck.update();
enemy.update();
lowBtn.update();
highBtn.update();
gameTrans.update();
if (intro.trans) {
intro.update();
}
}
void mousePressed() {
lowBtn.mousePressed();
highBtn.mousePressed();
}
void keyPressed() {
gameTrans.keyPressed();
intro.keyPressed();
}
void checkBtns() {
if (!v.hasVoted && intro.done && (lowBtn.clicked || highBtn.clicked)) {
if (lowBtn.clicked) {
v.vote = false;
v.hasVoted = true;
} else if (highBtn.clicked) {
v.vote = true;
v.hasVoted = true;
}
if (v.hasVoted) {
check();
}
}
}
/**
* Checks the cards of the player and enemy
*/
void check() {
v.roundNum++;
int order = player.hand.compareTo(deck.hand);
if (order == 0) {
v.check = Round.TIE;
return;
}
if ((v.vote && order == -1) || (!v.vote && order == 1)) { // Player wins
v.check = Round.WIN;
v.totalCorrect++;
v.currStreak++;
a.correct.jump(0);
// Update the highest streak
if (v.currStreak > v.highestStreak) {
v.highestStreak = v.currStreak;
}
// Increase the score
v.score += Math.pow((v.currStreak + 1), 2) * 100;
} else { // Enemy wins
v.check = Round.LOSS;
v.currStreak = 0;
a.wrong.jump(0);
}
}
public void push() {
pushMatrix();
pushStyle();
}
public void pop() {
popMatrix();
popStyle();
}