-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidterm.java
491 lines (489 loc) · 15.2 KB
/
midterm.java
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
// Story Name: Escape the Dark Dimension
// Programmer Name: Erin Hu
// Version Number: 11
import arc.*;
import java.awt.image.BufferedImage;
import java.awt.Color;
import java.awt.Font;
public class midterm{
public static void main(String[] args){
// Console
Console con = new Console("Escape the Dark Dimension", 1280, 720);
// Scene 1 Variables
String strChoice;
strChoice = "";
// Scene 2 Variables
int intGuess;
int intRand;
int intCount;
// Scene 3 Variables
String strTired;
int intLength2;
int intCount3;
double dblSwim;
dblSwim = 0;
double dblSwim2;
// NOTE: The scenes have numerical labels.
// NOTE: However, the scenes here are listed chronologically, based on how the story flows.
// Scene 8 Variables
String strName;
String strLetter;
int intCount2;
int intLength;
int intCheck;
intCheck = 0;
// Scene 10 Variables
int intCookies;
// Scene 4 Variables
double dblHyp;
// Scene 5 Variables
char chrFood;
// Font Variable
Font fntJosefin = con.loadFont("JosefinSans-Regular.ttf", 25); // (filename, fontsize)
con.setTextFont(fntJosefin);
// Scene 1
scene1(con);
con.println(" Do you \"give up\" or \"keep swimming\"?");
strChoice = con.readLine();
// If statement: choice - give up
if(strChoice.equalsIgnoreCase("give up")){
// Scene 2
con.clear();
scene2(con);
con.println(" You will enter a number between 1 and 3");
con.println(" inclusive to see if you can open it. ");
con.println(" ");
con.println(" You get 10 attempts.");
for(intCount = 1; intCount <= 10; intCount++){
intRand = (int)(Math.random() * 4 + 1);
con.println(" ");
con.println(" Guess "+intCount+":");
intGuess = con.readInt();
if(intGuess == intRand){
intCount = 11;
con.clear();
// Scene 8
scene8(con);
con.println(" Enter your name carefully: ");
strName = con.readLine();
intLength = strName.length();
for(intCount2 = intLength; intCount2 >= 1; intCount2--){
strLetter = strName.substring(intCount2 - 1, intCount2);
// con.println("test"+strLetter);
if(strLetter.equalsIgnoreCase("a") || strLetter.equalsIgnoreCase("e") || strLetter.equalsIgnoreCase("i") || strLetter.equalsIgnoreCase("o") || strLetter.equalsIgnoreCase("u")){
intCheck = intCheck + 0;
// con.println("test"+intCheck);
}else{
intCheck = intCheck + 1;
// con.println("test"+intCheck);
}
}
if(intCheck >= 1){
strName = "Not all vowels";
// con.println("test"+strName);
}else{
strName = "All vowels";
// con.println("test"+strName);
}
con.clear();
// If statement: choice - the player doesn't enter all vowels
if(strName.equals("Not all vowels")){
// Scene 9
con.clear();
scene9(con);
// Else statement: choice - the player enters all vowels
}else{
// Scene 10
con.clear();
scene10(con);
con.println("How many cookies do you take?");
intCookies = con.readInt();
// If statement: choice - player chooses 0 or 10 cookies
if(intCookies == 10 || intCookies == 0){
con.clear();
// Scene 9 (This is the second possible outcomes that lead to Scene 9)
scene9(con);
// Else statement: choice - player chooses 1-9 cookies
}else if(intCookies >= 1 && intCookies <= 9){
con.clear();
// Scene 11
scene11(con);
}
}
// Else statement: choice - the guessed integer does not match the random integer
}else if(intGuess != intRand && intCount == 10){
intCount = 11;
// Scene 7
con.clear();
scene7(con);
}
}
// Else if statement: choice - player inputs "keep swimming"
}else if(strChoice.equalsIgnoreCase("keep swimming")){
con.clear();
// Scene 3
scene3(con);
con.println(" How tired are you right now?");
con.println(" Answer with a phrase.");
strTired = con.readLine();
intLength2 = strTired.length();
for(intCount3 = intLength2; intCount3 > 0; intCount3--){
con.println(" Enter any double number to keep swimming: ");
dblSwim2 = con.readDouble();
dblSwim = dblSwim + dblSwim2;
// con.println("TEMP"+dblSwim);
if(dblSwim < 10){
con.println(" You're sinking!");
}else if(dblSwim >= 10 && dblSwim < 50){
con.println(" Keep going! Almost there!");
}else if(dblSwim >= 50 && dblSwim < 99){
con.println(" So close!");
}else{
intCount3 = 0;
}
}
// If statement: choice - dblSwim input is less than 100
if(dblSwim < 100){
// Scene 7
con.clear();
scene7(con);
// Else statement: choice - dblSwim input is more than 100
}else{
con.clear();
// Scene 4
scene4(con);
con.println(" Enter the hypotenuse: ");
dblHyp = con.readDouble();
// If statement: choice - player enters the hypotenuse
if(dblHyp == 10){
// con.println("test");
// Scene 5
con.clear();
scene5(con);
chrFood = con.getChar();
// con.println(chrFood);
// If statement: choice - char input > g
if(chrFood > 'g'){
// Scene 12
con.clear();
scene12(con);
// Else if statement: choice - char input <= g
}else if(chrFood <= 'g'){
// Scene 13
con.clear();
scene13(con);
}
}else{ // Else statement: player enters wrong hypotenuse
con.clear();
scene6(con);
}
}
}
}
// SCENE 1
public static void scene1(Console con){
// Images
BufferedImage imgScene1Background = con.loadImage("Scene1-1.jpg");
BufferedImage imgScene1Character = con.loadImage("Scene1-3.jpeg");
// Variables
int intCount1;
int intCount8; // intCount2 to intCount 7 are used for other scenes
int intCharacterY;
intCharacterY = 25;
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println(" ");
con.println(" An evil cube has transported you to the dark dimension and");
con.println(" wants to taunt you. If you survive the night, it will let");
con.println(" you out.");
con.println(" ");
con.println(" You woke up to find yourself drowning in an unknown liquid.");
// Background
con.drawImage(imgScene1Background,0,0);
// Animation loops
for(intCount8 = 0; intCount8 <= 3; intCount8++){
for(intCount1 = 0; intCount1 <= 27; intCount1++){
con.drawImage(imgScene1Background,0,0);
con.drawImage(imgScene1Character,0,intCharacterY);
con.repaint();
con.sleep(15);
intCharacterY = intCharacterY - 2;
}
for(intCount1 = 0; intCount1 <= 27; intCount1++){
con.drawImage(imgScene1Background,0,0);
con.drawImage(imgScene1Character,0,intCharacterY);
con.repaint();
con.sleep(15);
intCharacterY = intCharacterY + 2;
}
}
}
// SCENE 2
public static void scene2(Console con){
// Variables
BufferedImage imgScene2Character = con.loadImage("Scene2-1.jpg");
BufferedImage imgScene2Background = con.loadImage("Scene2-2.jpg");
int intCount2;
int intCount3;
int intBubbleY;
intBubbleY = 0;
int intBubbleY2;
intBubbleY2 = -80;
int intBubbleY3;
intBubbleY3 = -50;
// Background
con.drawImage(imgScene2Background, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println(" ");
con.println(" You sink, then find a button with a sliding");
con.println(" door.");
con.println(" ");
// Animation: person sinking
for(intCount3 = 0; intCount3 < 400; intCount3 = intCount3 + 8){
// Background
con.drawImage(imgScene2Background, 0, 0);
// Character
con.drawImage(imgScene2Character, 150, intCount3);
// Bubbles and custom RGB colour
con.setDrawColor(new Color(247, 175, 120));
con.fillOval(700, intBubbleY, 25, 25);
con.setDrawColor(new Color(237, 170, 130));
con.fillOval(750, intBubbleY2, 35, 35);
con.setDrawColor(new Color(227, 180, 136));
con.fillOval(800, intBubbleY3, 28, 28);
// Repaint
con.repaint();
con.sleep(33);
intBubbleY = intBubbleY + 8;
intBubbleY2 = intBubbleY2 + 8;
intBubbleY3 = intBubbleY3 + 8;
}
}
// SCENE 3
public static void scene3(Console con){
// Variables
BufferedImage imgScene3Background = con.loadImage("Scene3-1.jpg");
BufferedImage imgScene3Character = con.loadImage("Scene3-2.jpg");
// Images
con.drawImage(imgScene3Background,0,0);
con.drawImage(imgScene3Character,0,0);
// Text
con.println(" ");
con.println(" You are getting very tired. Can you swim out?");
}
// SCENE 4
public static void scene4(Console con){
// Variables
char chrRead;
int intCount4;
int intCount5;
int intCount6;
int intCount9;
int intEyebrowsY;
int intMouthY;
intEyebrowsY = 0;
intMouthY = -50;
BufferedImage imgScene4Background = con.loadImage("Scene4-1.jpg");
BufferedImage imgScene4Eyebrows = con.loadImage("Scene4-2.jpg");
BufferedImage imgScene4Mouth = con.loadImage("Scene4-3.jpg");
// Images
con.drawImage(imgScene4Background, 0, 0);
con.drawImage(imgScene4Eyebrows, 0, 0);
con.drawImage(imgScene4Mouth, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" Your swim to the shore has made you hungry.");
con.println(" A suspicious, carnivorous cube sits on a fridge.");
con.println(" The cube says that you can open the fridge if");
con.println(" you find the hypotenuse of a triangle with side");
con.println(" lengths 6 and 8. ");
// Animation
for(intCount6 = 0; intCount6 <= 4; intCount6++){
for(intCount4 = 0; intCount4 <= 10; intCount4++){
con.drawImage(imgScene4Background, 0, 0);
con.drawImage(imgScene4Eyebrows, 0, intEyebrowsY);
con.drawImage(imgScene4Mouth, 0, intMouthY);
con.repaint();
con.sleep(33);
intEyebrowsY = intEyebrowsY + 5;
// Eyebrows move back up
if(intEyebrowsY == 50){
for(intCount5 = 0; intCount5 <= 10; intCount5++){
con.drawImage(imgScene4Background, 0, 0);
con.drawImage(imgScene4Eyebrows, 0, intEyebrowsY);
con.repaint();
con.sleep(33);
intEyebrowsY = intEyebrowsY - 5;
}
}
}
}
}
// SCENE 5
public static void scene5(Console con){
// Variables
BufferedImage imgScene5Background = con.loadImage("Scene5-1.jpg");
// Image
con.drawImage(imgScene5Background, 0, 0);
// Text
con.println(" ");
con.println(" Since you opened the fridge, you stuff yourself with food.");
con.println(" The cube asks you how the food was. Press any letter key");
con.println(" to respond to the cube.");
}
// SCENE 6
public static void scene6(Console con){
// Variables
int intCount6;
int intCount7;
intCount7 = 0;
int intMouthY;
intMouthY = 0;
BufferedImage imgScene13Background = con.loadImage("Scene13-1.jpg");
BufferedImage imgScene13Mouth = con.loadImage("Scene13-2.jpg");
// Images
con.drawImage(imgScene13Background, 0, 0);
con.drawImage(imgScene13Mouth, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println(" The cube was hoping you could open the fridge,");
con.println(" but you did not get the correct answer. The cube");
con.println(" is hungry too, so it eats you. Game over.");
// Animation
while(intCount7 == 0){
for(intCount6 = 0; intCount6 <= 33; intCount6++){
con.drawImage(imgScene13Background, 0, 0);
con.drawImage(imgScene13Mouth, 0, intMouthY);
con.repaint();
con.sleep(15);
intMouthY = intMouthY - 2;
}
for(intCount6 = 0; intCount6 <= 33; intCount6++){
con.drawImage(imgScene13Background, 0, 0);
con.drawImage(imgScene13Mouth, 0, intMouthY);
con.repaint();
con.sleep(15);
intMouthY = intMouthY + 2;
}
}
}
// SCENE 7
public static void scene7(Console con){
// Image and image variable
BufferedImage imgScene7Background = con.loadImage("Scene7-1.jpg");
con.drawImage(imgScene7Background, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println(" ");
con.println("All this swimming has tired you out.");
con.println("You run out of air and energy. Your consciousness slowly");
con.println("slips away as you fight to survive. A fish eats you, and");
con.println("you die. Game over.");
}
// SCENE 8
public static void scene8(Console con){
// Images
BufferedImage imgScene8Background = con.loadImage("Scene8-1.jpg");
con.drawImage(imgScene8Background, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println(" ");
con.println(" You open the door and quickly go in. A giant cube asks");
con.println(" what your name is. It tells you to enter by only using");
con.println(" five specific letters There are only five of these.");
con.println(" They have unique sounds. They are not consonants.");
}
// SCENE 9
public static void scene9(Console con){
// Images
BufferedImage imgScene8Background = con.loadImage("Scene9.jpg");
con.drawImage(imgScene8Background, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println(" ");
con.println(" The cube is mad. It eats you.");
con.println(" Unfortunately, you will never see your home");
con.println(" again. Game over.");
}
// SCENE 10
public static void scene10(Console con){
// Images
BufferedImage imgScene10Background = con.loadImage("Scene10-1.jpg");
con.drawImage(imgScene10Background, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println(" ");
con.println(" Before you go, the cube wants to give you a treat.");
con.println(" It conjures 10 cookies. The cube asks, \"How many ");
con.println(" do you want?\" Choose carefully because the cube has");
con.println(" has a short temper.");
}
// SCENE 11
public static void scene11(Console con){
// Images
BufferedImage imgScene10Background = con.loadImage("Scene11.jpg");
con.drawImage(imgScene10Background, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println(" ");
con.println(" The cube decides that it is pleased with you. You");
con.println(" survive. The cube transports you through a portal");
con.println(" back to your home.");
}
// SCENE 12
public static void scene12(Console con){
// Images
BufferedImage imgScene8Background = con.loadImage("Scene12.jpg");
con.drawImage(imgScene8Background, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println(" ");
con.println(" The cube is happy. It lets you live, then transports");
con.println(" you back home.");
}
// SCENE 13
public static void scene13(Console con){
// Variables
int intCount6;
int intCount7;
intCount7 = 0;
int intMouthY;
intMouthY = 0;
BufferedImage imgScene13Background = con.loadImage("Scene13-1.jpg");
BufferedImage imgScene13Mouth = con.loadImage("Scene13-2.jpg");
// Images
con.drawImage(imgScene13Background, 0, 0);
con.drawImage(imgScene13Mouth, 0, 0);
// Text
con.setTextColor(Color.BLACK);
con.println(" ");
con.println("The cube is offended. It eats you. Game over.");
// Animation
while(intCount7 == 0){
for(intCount6 = 0; intCount6 <= 33; intCount6++){
con.drawImage(imgScene13Background, 0, 0);
con.drawImage(imgScene13Mouth, 0, intMouthY);
con.repaint();
con.sleep(15);
intMouthY = intMouthY - 2;
}
for(intCount6 = 0; intCount6 <= 33; intCount6++){
con.drawImage(imgScene13Background, 0, 0);
con.drawImage(imgScene13Mouth, 0, intMouthY);
con.repaint();
con.sleep(15);
intMouthY = intMouthY + 2;
}
}
}
}