-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnap.pde
198 lines (150 loc) · 3.94 KB
/
Snap.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import java.util.*;
import java.lang.reflect.Field;
import processing.sound.*;
import controlP5.*;
// * CONSTANTS
public static final int h = 1000;
public static final int w = 1000;
public static final int ch = 500;
public static final int cw = 500;
// * VARIABLES
public boolean doingIntro = true;
public boolean transitioning = false;
public boolean turnOver = true;
public boolean roundOver = false;
public int startTurn = ((Math.random() * 2) > 1.0) ? 1 : 2;
public int curTurn = startTurn;
public int curCardIndex = -1;
public boolean gOver = false;
// The highest round the game can reach before ending
public int maxRound = 6;
public int curRound = 1;
public int numTurns = curRound;
// * COLORS
public static final color bg = #1e293b;
// * Util classes
public Assets a = new Assets();
// * Librarry classes
public ControlP5 cp5;
// * Transition classes
public TransitionIn transIn = new TransitionIn(this);
public TransitionOut transOut = new TransitionOut(this);
// * Game classes
public StartUp startUp = new StartUp(this);
public Intro intro = new Intro(this);
public Dealer dealer = new Dealer();
public Player p1 = new Player(this, 1);
public Player p2 = new Player(this, 2);
public Player curPlayer = startTurn == 1 ? p1 : p2;
public Turn turn = new Turn(this);
public Location l1 = new Location(this, -1);
public Location l2 = new Location(this, 0);
public Location l3 = new Location(this, 1);
public SkipBtn skipBtn = new SkipBtn(this);
public Header header = new Header(this);
public Tooltip tooltip = new Tooltip(this);
public GameOver gameOver = new GameOver(this);
void setup() {
size(1000, 1000);
procSet();
// * Setup variables and assets
a.setup(this);
cp5 = new ControlP5(this);
// * SETUP CLASSES
dealCards();
p1.setup();
p2.setup();
startUp.setup();
intro.setup();
l1.setup();
l2.setup();
l3.setup();
skipBtn.setup();
turn.setup();
header.setup();
tooltip.setup();
gameOver.setup();
}
void draw() {
background(bg);
// If the game over transition is done only update the game over screen to avoid redrawing hidden items to the screen
if (gOver && gameOver.paused) {
gameOver.update();
return;
}
intro.update();
if (doingIntro) {
return;
}
// Do game updates here!
startUp.update();
if (!startUp.done) return;
if (turnOver) {
turn.update();
return;
}
if (turnOver) return;
// Draw the background
image(a.bg, cw, ch);
if (curTurn == 1) {
p1.update();
} else if (curTurn == 2) {
p2.update();
} else {
println("aaaaaaaaaa wtf happened to the turn?");
}
l1.update();
l2.update();
l3.update();
skipBtn.update();
header.update();
tooltip.update();
if (skipBtn.clicked) {
turnOver = true;
curTurn = curTurn == 1 ? 2 : 1;
curPlayer = curTurn == 1 ? p1 : p2;
curCardIndex = -1;
gOver = isGameOver();
if (curTurn == startTurn) {
curRound++;
if (curRound >= maxRound) {
gOver = true;
}
}
numTurns = curRound;
}
gameOver.update();
}
/**
* Sets the default settings for drawing with processing
*/
void procSet() {
background(0);
shapeMode(CENTER);
textAlign(CENTER);
imageMode(CENTER);
noStroke();
// Default fill color is white
fill(255);
}
void dealCards() {
dealer.deal(p1.hand, 5);
dealer.deal(p1.deck, 7);
dealer.deal(p2.hand, 5);
dealer.deal(p2.deck, 7);
// Print out the cards of the player for debuggging
// printCards();
}
// Print out the cards of the player for debuggging
void printCards() {
println("Player 1: \n" + p1 + "\n\n");
println("Player 2: \n" + p2 + "\n\n");
}
boolean isGameOver() {
// ! Uncomment this line for debbugging the game over screen
// return true;
boolean hasSpace = l1.cards.size() < 2 || l2.cards.size() < 4 || l3.cards.size() < 4;
boolean hasCards = p1.hasCards() || p2.hasCards();
boolean hasSpecialCards = p1.hasSpecialCard() || p2.hasSpecialCard();
return (!hasSpace && !hasCards) && !hasSpecialCards;
}