-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJitsuGame.java
More file actions
392 lines (314 loc) · 12.5 KB
/
JitsuGame.java
File metadata and controls
392 lines (314 loc) · 12.5 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
// Author: Akshavi Baskaran Purpose: Jitsu Game Class Date: 12-27-2022
// JitsuGame.java
import java.awt.Color;
// JitsuGame class
// This is the model of the Element Jitsu game
// Manages rules of the game, comparing cards, card inventory, and who is winning
public class JitsuGame extends Hand{
Color peach = new Color(255,218,185); // new peach colour
private boolean playerWin = false; // boolean for when player has won
Color [] winF = {peach, peach, peach}; // inventory array for player's fire cards
Color[] winW = {peach, peach, peach}; // inventory array for player's water cards
Color[] winS = {peach, peach, peach}; // inventory array for player's snow cards
boolean compWin = false; // boolean for when computer has won
Color [] winComF = {peach, peach, peach}; // inventory array for computer's fire cards
Color[] winComW = {peach, peach, peach}; // inventory array for computer's water cards
Color[] winComS = {peach, peach, peach}; // inventory array for computer's snow cards
// compare method; returns integer
// compare the computer card with the player picked card
public Integer compare() {
// if statement: if temp card is equal to comp card, compare the values of the cards
// return (1) means player won, (2) means comp won, (0) means tie
if (temp.element == compCard.element) {
// if statement: if temp card is greater than comp card
if (temp.value > compCard.value) {
return 1;
} // end if
// if statement: if temp card is smaller than comp card
if (temp.value < compCard.value) {
return 2;
} // end if
return 0; // if cards are equal, return 0 (tie)
} // end if statement comparing values
// else statement: comparing the elements of the cards
else {
// if: compare element if temp card element is fire
if (temp.element == "fire") {
// if comp card element is snow, player wins
if (compCard.element == "snow") {
return 1;
} // end if
// else computer wins
else
return 2;
} // end if
// else if: compare element if temp card element is water
else if (temp.element == "water") {
// if comp card element is fire, player wins
if (compCard.element == "fire") {
return 1;
} // end if
// else computer wins
else
return 2;
} // end else if
// else if: compare element if temp card element is snow
else if (temp.element == "snow") {
// if comp card element is water, player wins
if (compCard.element == "water") {
return 1;
}
// else computer wins
else
return 2;
} // end else
return 2;
} // end else statment
} // end compare method
// addPlayerInventory method: array of UNIQUE colors for each element for the PLAYER
// inventory for each element, and change from peach to a different color each time player wins
public void addPlayerInventory() {
// if statement: if temp card element is fire, input it into the winning fire array
if (temp.element == "fire") {
// if first colour in array is peach, then add the temp card colour
if (winF[0] == peach) {
winF[0] = temp.color;
playerWin = false; // boolean player has not won
} // end if
// else if second colour in array is peach, then add the temp card colour
else if (winF[1] == peach) {
// if the temp card colour is NOT equal to the first colour in the array, then add the temp card colour
if (winF[0] != temp.color) {
winF[1] = temp.color;
playerWin = false; // boolean player has not won
} // end if
// else keep the colour as peach in the array
else {
winF[1] = peach;
playerWin = false; // player not won
} // end else
} // end else if
// else if third colour is peach, then add the temp card color
else if (winF[2] == peach) {
// if the temp card color is NOT equal to first AND second colour in the array, then add the temp card color
if (winF[0] != temp.color && winF[1] != temp.color) {
winF[2] = temp.color;
playerWin = true; // player has won
} // end if statement
// else keep the colour as peach
else {
winF[2] = peach;
playerWin = false; // player has not won
} // end else
} // end else if
} // if statement for fire
// if statement: if temp card element is water, input it into the winning water array
if (temp.element == "water") {
// if first colour in array is peach, then add the temp card colour
if (winW[0] == peach) {
winW[0] = temp.color;
playerWin = false; // boolean player has not won
} // end if
// else if second colour in array is peach, then add the temp card colour
else if (winW[1] == peach) {
// if the temp card colour is NOT equal to the first colour in the array, then add the temp card colour
if (winW[0] != temp.color) {
winW[1] = temp.color;
playerWin = false; // boolean player has not won
} // end if
// else keep the colour as peach in the array
else {
winW[1] = peach;
playerWin = false; // player not won
} // end else
} // end else if
// else if third colour is peach, then add the temp card color
else if (winW[2] == peach) {
// if the temp card color is NOT equal to first AND second colour in the array, then add the temp card color
if (winW[0] != temp.color && winW[1] != temp.color) {
winW[2] = temp.color;
playerWin = true; // player has won
} // end if statement
// else keep the colour as peach
else {
winW[2] = peach;
playerWin = false; // player has not won
} // end else
} // end else if
} // if statement for water
// if statement: if temp card element is snow, input it into the winning snow array
if (temp.element == "snow") {
// if first colour in array is peach, then add the temp card colour
if (winS[0] == peach) {
winS[0] = temp.color;
playerWin = false; // player has not won
} // end if
// else if second colour in array is peach, then add the temp card colour
else if (winS[1] == peach) {
// if the temp card colour is NOT equal to the first colour in the array, then add the temp card colour
if (winS[0] != temp.color) {
winS[1] = temp.color;
playerWin = false; // boolean player has not won
} // end if
// else keep the colour as peach in the array
else {
winS[1] = peach;
playerWin = false; // player not won
} // end else
} // end else if
// else if third colour is peach, then add the temp card color
else if (winS[2] == peach) {
// if the temp card color is NOT equal to first AND second colour in the array, then add the temp card color
if (winS[0] != temp.color && winS[1] != temp.color) {
winS[2] = temp.color;
playerWin = true; // player has won
} // end if statement
// else keep the colour as peach
else {
winS[2] = peach;
playerWin = false; // player has not won
} // end else
} // end else if
} // if statement for snow
} // end addPlayerInventory method
// addCompInventory method: array of UNIQUE colors for each element for the COMPUTER
// inventory for each element, and change from peach to a different color each time computer wins
public void addCompInventory() {
// if statement: if temp card element is fire, input it into the winning fire array
if (compCard.element == "fire") {
// if first colour in array is peach, then add the comp card colour
if (winComF[0] == peach) {
winComF[0] = compCard.color;
compWin = false; // boolean computer has not won
} // end if
// else if second colour in array is peach, then add the comp card colour
else if (winComF[1] == peach) {
// if the comp card colour is NOT equal to the first colour in the array, then add the comp card colour
if (winComF[0] != compCard.color) {
winComF[1] = compCard.color;
compWin = false; // boolean computer has not won
} // end if
// else keep the colour as peach in the array
else {
winComF[1] = peach;
compWin = false; // computer not won
} // end else
} // end else if
// else if third colour is peach, then add the comp card color
else if (winComF[2] == peach) {
// if the comp card color is NOT equal to first AND second colour in the array, then add the comp card color
if (winComF[0] != compCard.color && winComF[1] != compCard.color) {
winComF[2] = compCard.color;
compWin = true; // computer has won
} // end if statement
// else keep the colour as peach
else {
winComF[2] = peach;
compWin = false; // computer has not won
} // end else
} // end else if
} // if statement for fire
// if statement: if comp card element is water, input it into the winning water array
if (compCard.element == "water") {
// if first colour in array is peach, then add the comp card colour
if (winComW[0] == peach) {
winComW[0] = compCard.color;
compWin = false; // boolean computer has not won
} // end if
// else if second colour in array is peach, then add the comp card colour
else if (winComW[1] == peach) {
// if the comp card colour is NOT equal to the first colour in the array, then add the comp card colour
if (winComW[0] != compCard.color) {
winComW[1] = compCard.color;
compWin = false; // boolean player has not won
} // end if
// else keep the colour as peach in the array
else {
winComW[1] = peach;
compWin = false; // computer not won
} // end else
} // end else if
// else if third colour is peach, then add the comp card color
else if (winComW[2] == peach) {
// if the comp card color is NOT equal to first AND second colour in the array, then add the comp card color
if (winComW[0] != compCard.color && winComW[1] != compCard.color) {
winComW[2] = compCard.color;
compWin = true; // computer has won
} // end if statement
// else keep the colour as peach
else {
winComW[2] = peach;
compWin = false; // computer has not won
} // end else
} // end else if
} // if statement for water
// if statement: if comp card element is snow, input it into the winning snow array
if (compCard.element == "snow") {
// if first colour in array is peach, then add the comp card colour
if (winComS[0] == peach) {
winComS[0] = compCard.color;
compWin = false; // computer has not won
} // end if
// else if second colour in array is peach, then add the comp card colour
else if (winComS[1] == peach) {
// if the comp card colour is NOT equal to the first colour in the array, then add the comp card colour
if (winComS[0] != compCard.color) {
winComS[1] = compCard.color;
compWin = false; // boolean computer has not won
} // end if
// else keep the colour as peach in the array
else {
winComS[1] = peach;
compWin = false; // computer not won
} // end else
} // end else if
// else if third colour is peach, then add the comp card color
else if (winComS[2] == peach) {
// if the compcard color is NOT equal to first AND second colour in the array, then add the comp card color
if (winComS[0] != compCard.color && winComS[1] != compCard.color) {
winComS[2] = compCard.color;
compWin = true; // player has won
} // end if statement
// else keep the colour as peach
else {
winComS[2] = peach;
compWin = false; // computerhas not won
} // end else
} // end else if
} // if statement for snow
}
// hasWon method; return who won, player or computer, or none.
// check if won
public String hasWon() {
String status = ""; // string to identify who has won
// if player win is true, string status is you
if (playerWin == true) {
status = "You";
} // end if
// else if comp win is true, string status is computer
else if (compWin == true) {
status = "Computer";
} // end else if
// else string status is none
else {
status = "none";
} // end else
return status; // return status string
} // end hasWon method
// restart method
// method for when player wants to play again
public void restart() {
// set all inventory arrays as PEACH colour
for(int i = 0; i<3 ; i++){
winF[i] = peach;
winW[i] = peach;
winS[i] = peach;
winComF[i] = peach;
winComW[i] = peach;
winComS[i] = peach;
} // end for loop
playerWin = false; // player has not won
compWin = false; // computer has not won
getFirstHand(); // get a new first hand
} // end restart method
} // end class JitsuGame