-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoulArrayGUI.java
More file actions
851 lines (719 loc) · 29.5 KB
/
soulArrayGUI.java
File metadata and controls
851 lines (719 loc) · 29.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
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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Collections;
public class soulArrayGUI {
JFrame window;
JPanel titleNamePanel, startButtonPanel, mainTextPanel, storyContinuePanel, menuPanel, menuButton, coinsPanel,
goBackToMainPanel, userHpLabel, oppHpLabel, bodyTextPanel, fighPassPanel, turnPanel;
JLabel titleTextLabel, menuTitle, coinsText, userHp, oppHp, turnText;
Font titleFont = new Font("Times New Roman", Font.PLAIN, 90);
Font normalFont = new Font("Times New Roman", Font.PLAIN, 30);
Font subFont = new Font("Times New Roman", Font.PLAIN, 60);
JButton startButton, storyButton, buy, sell, play, quit, goBackToMainB, fight, pass, cont;
JTextArea mainTextArea, messageTextArea, bodyTextArea;
// organs
JPanel organsButtons;
JButton brain, guts, hands, heart, legs, eyes, lungs, kidney, teeth, skin;
// horses
JPanel horses;
JButton cerberus, persephone, hades, voskopoulos, tom;
// horse racing panels
JLabel hrTitle, hrSubtitle, hrEnterBet;
JPanel hrTitlePanel, hrSubPanel, hrBetPanel;
// rps panels
JLabel choice;
// rps elements
JButton fire, water, earth;
// games
JPanel gamesButtons;
JButton danceWdevilB, horseRacingB, rockPaperScissorsB;
TitleScreenHandler tsHandler = new TitleScreenHandler();
ContinueButtonHandler cbHandler = new ContinueButtonHandler();
PlayHandler playHandler = new PlayHandler();
SellHandler sellHandler = new SellHandler();
QuitHandler quitHandler = new QuitHandler();
BuyHandler buyHandler = new BuyHandler();
GoBackHandler goBackHandler = new GoBackHandler();
DanceWDevilHandler dwdHandler = new DanceWDevilHandler();
HorseRacingHandler hrHandler = new HorseRacingHandler();
ElementalHandler eHandler = new ElementalHandler();
ArrayList<String> mainArray = new ArrayList<>(Arrays.asList("BRAIN", "GUTS", "HANDS", "HEART", "LEGS"));
ArrayList<String> sellArray = new ArrayList<>(Arrays.asList("EYES", "LUNGS", "KIDNEY", "TEETH", "SKIN"));
ArrayList<Integer> mainArrayPrice = new ArrayList<>(Arrays.asList(2000, 1800, 1500, 3500, 2300));
ArrayList<Integer> sellArrayPrice = new ArrayList<>(Arrays.asList(800, 1250, 1000, 750, 900));
private int coins = 50000;
private int userHpAmount = 1000;
private int oppHpAmount = 1000;
ArrayList<String> boughtOrgans = new ArrayList<>();
ArrayList<String> soldOrgans = new ArrayList<>();
public static void main(String[] args) {
new soulArrayGUI();
}
public soulArrayGUI() {
window = new JFrame();
window.setSize(800, 600);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setBackground(Color.black);
window.setLayout(null);
window.getContentPane();
titleNamePanel = new JPanel();
titleNamePanel.setBounds(100, 100, 600, 150);
titleNamePanel.setBackground(Color.black);
titleTextLabel = new JLabel("SOUL ARRAY");
titleTextLabel.setForeground(Color.white);
titleTextLabel.setFont(titleFont);
startButtonPanel = new JPanel();
startButtonPanel.setBounds(300, 400, 200, 100);
startButtonPanel.setBackground(Color.black);
startButton = new JButton("START");
startButton.setBackground(Color.black);
startButton.setForeground(Color.white);
startButton.setFont(normalFont);
startButton.setFocusPainted(false);
startButton.addActionListener(tsHandler);
titleNamePanel.add(titleTextLabel);
startButtonPanel.add(startButton);
window.add(titleNamePanel);
window.add(startButtonPanel);
// go back to main menu button
goBackToMainPanel = new JPanel();
goBackToMainPanel.setBounds(10, 10, 100, 50);
goBackToMainPanel.setBackground(Color.black);
goBackToMainB = new JButton("Menu");
goBackToMainB.setBackground(Color.black);
goBackToMainB.setForeground(Color.white);
goBackToMainB.setFont(new Font("Times New Roman", Font.PLAIN, 20));
goBackToMainB.setFocusPainted(false);
goBackToMainB.addActionListener(goBackHandler);
goBackToMainPanel.add(goBackToMainB);
goBackToMainPanel.setVisible(false); // Initially hidden
window.add(goBackToMainPanel);
window.setVisible(true);
}
public void storyScreen() {
titleNamePanel.setVisible(false);
startButtonPanel.setVisible(false);
mainTextPanel = new JPanel();
mainTextPanel.setBounds(200, 200, 600, 150);
mainTextPanel.setBackground(Color.black);
mainTextPanel.setLayout(new BorderLayout());
window.add(mainTextPanel);
mainTextArea = new JTextArea("You've sold your soul to me");
mainTextArea.setBackground(Color.black);
mainTextArea.setForeground(Color.white);
mainTextArea.setFont(normalFont);
mainTextArea.setLineWrap(true);
mainTextPanel.add(mainTextArea, BorderLayout.NORTH);
messageTextArea = new JTextArea();
messageTextArea.setBackground(Color.black);
messageTextArea.setForeground(Color.green);
messageTextArea.setFont(normalFont);
messageTextArea.setLineWrap(true);
mainTextPanel.add(messageTextArea, BorderLayout.CENTER);
storyContinuePanel = new JPanel();
storyContinuePanel.setBounds(225, 350, 300, 150);
storyContinuePanel.setBackground(Color.black);
window.add(storyContinuePanel);
storyButton = new JButton("continue");
storyButton.setBackground(Color.black);
storyButton.setForeground(Color.white);
storyButton.setFont(normalFont);
storyButton.setFocusPainted(false);
storyButton.addActionListener(cbHandler);
storyContinuePanel.add(storyButton);
}
public void mainMenu() {
if (storyContinuePanel != null)
storyContinuePanel.setVisible(false);
if (mainTextPanel != null)
mainTextPanel.setVisible(false);
if (coinsPanel != null)
coinsPanel.setVisible(false);
if (organsButtons != null)
organsButtons.setVisible(false);
if (gamesButtons != null)
gamesButtons.setVisible(false);
if (userHpLabel != null)
userHpLabel.setVisible(false);
if (oppHpLabel != null)
oppHpLabel.setVisible(false);
if (bodyTextPanel != null)
bodyTextPanel.setVisible(false);
if (fighPassPanel != null)
fighPassPanel.setVisible(false);
if (turnPanel != null)
turnPanel.setVisible(false);
if (hrTitlePanel != null)
hrTitlePanel.setVisible(false);
if (hrSubPanel != null)
hrSubPanel.setVisible(false);
if (hrBetPanel != null)
hrBetPanel.setVisible(false);
if (horses != null)
horses.setVisible(false);
if (messageTextArea != null)
messageTextArea.setText("");
menuPanel = new JPanel();
menuPanel.setBounds(100, 100, 600, 150);
menuPanel.setBackground(Color.black);
menuTitle = new JLabel("MAIN MENU");
menuTitle.setForeground(Color.white);
menuTitle.setFont(titleFont);
menuPanel.add(menuTitle);
window.add(menuPanel);
menuButton = new JPanel();
menuButton.setBounds(225, 350, 300, 150);
menuButton.setBackground(Color.black);
menuButton.setLayout(new GridLayout(2, 2));
window.add(menuButton);
play = new JButton("Play");
play.setBackground(Color.black);
play.setForeground(Color.green);
play.setFont(normalFont);
play.addActionListener(playHandler);
play.setFocusPainted(false);
quit = new JButton("Quit");
quit.setBackground(Color.black);
quit.setForeground(Color.red);
quit.setFont(normalFont);
quit.addActionListener(quitHandler);
quit.setFocusPainted(false);
buy = new JButton("Buy");
buy.setBackground(Color.black);
buy.setForeground(Color.white);
buy.setFont(normalFont);
buy.addActionListener(buyHandler);
buy.setFocusPainted(false);
sell = new JButton("Sell");
sell.setBackground(Color.black);
sell.setForeground(Color.white);
sell.setFont(normalFont);
sell.addActionListener(sellHandler);
sell.setFocusPainted(false);
menuButton.add(play);
menuButton.add(quit);
menuButton.add(buy);
menuButton.add(sell);
goBackToMainPanel.setVisible(false);
}
public void games() {
goBackToMainPanel.setVisible(true);
if (menuPanel != null)
menuPanel.setVisible(false);
if (menuButton != null)
menuButton.setVisible(false);
mainTextPanel.setVisible(true);
mainTextArea.setText("Which game do you want to play?");
coinsPanel = new JPanel();
coinsPanel.setBounds(80, 100, 600, 150);
coinsPanel.setBackground(Color.black);
coinsText = new JLabel();
coinsText.setText("Coins: " + coins);
coinsText.setForeground(Color.yellow);
coinsText.setFont(normalFont);
coinsPanel.add(coinsText);
gamesButtons = new JPanel();
gamesButtons.setBounds(225, 350, 300, 150);
gamesButtons.setBackground(Color.black);
gamesButtons.setLayout(new GridLayout(3, 3));
window.add(gamesButtons);
danceWdevilB = choiceButton("Dance with the Devil");
danceWdevilB.addActionListener(dwdHandler);
horseRacingB = choiceButton("Horse Racing");
horseRacingB.addActionListener(hrHandler);
rockPaperScissorsB = choiceButton("Elemental Exchange");
rockPaperScissorsB.addActionListener(eHandler);
gamesButtons.add(danceWdevilB);
gamesButtons.add(horseRacingB);
gamesButtons.add(rockPaperScissorsB);
window.add(coinsPanel);
}
public void danceWdevil() {
if (gamesButtons != null)
gamesButtons.setVisible(false);
if (menuButton != null)
menuButton.setVisible(false);
if (mainTextPanel != null)
mainTextPanel.setVisible(false);
coinsPanel.setBounds(270, 80, 200, 50);
userHpLabel = new JPanel();
userHpLabel.setBounds(10, 120, 200, 50);
userHpLabel.setBackground(Color.red);
userHp = new JLabel("HP: " + userHpAmount);
userHp.setForeground(Color.white);
userHp.setFont(normalFont);
userHpLabel.add(userHp);
window.add(userHpLabel);
oppHpLabel = new JPanel();
oppHpLabel.setBounds(550, 120, 200, 50);
oppHpLabel.setBackground(Color.blue);
oppHp = new JLabel("Devil's HP: " + oppHpAmount);
oppHp.setForeground(Color.red);
oppHp.setFont(normalFont);
oppHpLabel.add(oppHp);
window.add(oppHpLabel);
turnPanel = new JPanel();
turnPanel.setBounds(280, 170, 200, 50);
turnPanel.setBackground(Color.blue);
String userTurn = "Your turn";
String devilTurn = "Opponent's turn";
turnText = new JLabel(userTurn);
turnText.setForeground(Color.red);
turnText.setFont(normalFont);
turnPanel.add(turnText);
window.add(turnPanel);
bodyTextPanel = new JPanel();
bodyTextPanel.setBounds(40, 250, 700, 150);
bodyTextPanel.setBackground(Color.red);
bodyTextPanel.setLayout(new BorderLayout());
window.add(bodyTextPanel);
bodyTextArea = new JTextArea(
"You inflicted bla bnla bla\nYou inflicted bla bnla bla\nYou inflicted bla bnla bla\nYou inflicted bla bnla bla");
bodyTextArea.setBackground(Color.green);
bodyTextArea.setForeground(Color.white);
bodyTextArea.setFont(normalFont);
bodyTextArea.setLineWrap(true);
bodyTextPanel.add(bodyTextArea, BorderLayout.NORTH);
fighPassPanel = new JPanel();
fighPassPanel.setBounds(150, 450, 500, 50);
fighPassPanel.setBackground(Color.pink);
fighPassPanel.setLayout(new GridLayout(1, 3));
JButton fight = new JButton("FIGHT");
fight.setBackground(Color.green);
fight.setForeground(Color.white);
fight.setFont(normalFont);
fight.setFocusPainted(false);
JButton pass = new JButton("Pass");
pass.setBackground(Color.red);
pass.setForeground(Color.white);
pass.setFont(normalFont);
pass.setFocusPainted(false);
JButton cont = new JButton(">");
cont.setBackground(Color.orange);
cont.setForeground(Color.white);
cont.setFont(normalFont);
cont.setFocusPainted(false);
fighPassPanel.add(fight);
fighPassPanel.add(cont);
fighPassPanel.add(pass);
window.add(fighPassPanel);
}
public void horseRacing() {
if (gamesButtons != null)
gamesButtons.setVisible(false);
if (menuButton != null)
menuButton.setVisible(false);
if (mainTextPanel != null)
mainTextPanel.setVisible(false);
coinsPanel.setBounds(300, 80, 200, 50);
hrTitlePanel = new JPanel();
hrTitlePanel.setBounds(150, 150, 500, 75);
hrTitlePanel.setBackground(Color.black);
hrTitle = new JLabel("Horse Racing");
hrTitle.setForeground(Color.red);
hrTitle.setFont(subFont);
hrTitlePanel.add(hrTitle);
window.add(hrTitlePanel);
hrSubPanel = new JPanel();
hrSubPanel.setBounds(150, 240, 500, 80);
hrSubPanel.setBackground(Color.black);
hrSubtitle = new JLabel("Pick your horse");
hrSubtitle.setForeground(Color.white);
hrSubtitle.setFont(normalFont);
hrSubPanel.add(hrSubtitle);
window.add(hrSubPanel);
horses = new JPanel();
horses.setBounds(250, 350, 300, 150);
horses.setBackground(Color.black);
horses.setLayout(new GridLayout(5, 1));
window.add(horses);
final String[] selectedHorse = { "" };
cerberus = choiceButton("Cerberus");
persephone = choiceButton("Persephone");
hades = choiceButton("Hades");
voskopoulos = choiceButton("Voskopoulos");
tom = choiceButton("Tom");
cerberus.addActionListener(e -> {
selectedHorse[0] = "Cerberus";
horses.setVisible(false);
hrSubPanel.setVisible(false);
});
persephone.addActionListener(e -> {
selectedHorse[0] = "Persephone";
horses.setVisible(false);
hrSubPanel.setVisible(false);
});
hades.addActionListener(e -> {
selectedHorse[0] = "Hades";
horses.setVisible(false);
hrSubPanel.setVisible(false);
});
voskopoulos.addActionListener(e -> {
selectedHorse[0] = "Voskopoulos";
horses.setVisible(false);
hrSubPanel.setVisible(false);
});
tom.addActionListener(e -> {
selectedHorse[0] = "Tom";
horses.setVisible(false);
hrSubPanel.setVisible(false);
});
horses.add(cerberus);
horses.add(persephone);
horses.add(hades);
horses.add(voskopoulos);
horses.add(tom);
hrBetPanel = new JPanel();
hrBetPanel.setBounds(150, 240, 500, 80);
hrBetPanel.setBackground(Color.black);
hrEnterBet = new JLabel("Enter amount to bet.");
hrEnterBet.setForeground(Color.white);
hrEnterBet.setFont(normalFont);
hrBetPanel.add(hrEnterBet);
window.add(hrBetPanel);
// add a text field here that only accepts integers. there is also a button
// underneath it entitled "ENTER". if the user inputs an int, and clicks ENTER,
// it will be stored in a variable.
// else, if the field is blank or the input isn't an integer or the input equals
// 0, display an error message and wait until the user inputs a valid input
// again.
}
public void Elemental() {
if (gamesButtons != null)
gamesButtons.setVisible(false);
if (menuButton != null)
menuButton.setVisible(false);
if (mainTextPanel != null)
mainTextPanel.setVisible(false);
coinsPanel.setBounds(300, 80, 200, 50);
choice = new JLabel();
choice.setBounds(150, 350, 500, 100);
choice.setBackground(Color.black);
choice.setLayout(new GridLayout(1, 3));
window.add(choice);
fire = choiceButton("Fire");
water = choiceButton("Water");
earth = choiceButton("Earth");
choice.add(fire);
choice.add(water);
choice.add(earth);
fire.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
playGame("Fire");
}
});
water.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
playGame("Water");
}
});
earth.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
playGame("Earth");
}
});
}
private void playGame(String userChoice) {
String[] choices = { "Fire", "Water", "Earth" };
Random random = new Random();
String computerChoice = choices[random.nextInt(choices.length)];
String result;
if (userChoice.equals(computerChoice)) {
result = "It's a draw!";
} else if ((userChoice.equals("Fire") && computerChoice.equals("Earth")) ||
(userChoice.equals("Water") && computerChoice.equals("Fire")) ||
(userChoice.equals("Earth") && computerChoice.equals("Water"))) {
result = "You win!";
coins += 50;
coinsText.setText("Coins: " + coins);
} else {
result = "You lose!";
coins -= 50;
coinsText.setText("Coins: " + coins);
}
JOptionPane.showMessageDialog(window,
"You chose " + userChoice + "\nComputer chose " + computerChoice + "\n" + result);
}
public JButton choiceButton(String text) {
JButton button = new JButton(text);
button.setBackground(Color.black);
button.setForeground(Color.white);
button.setFont(normalFont);
button.setFocusPainted(false);
return button;
}
public void buy() {
goBackToMainPanel.setVisible(true);
if (menuPanel != null)
menuPanel.setVisible(false);
if (menuButton != null)
menuButton.setVisible(false);
mainTextPanel.setVisible(true);
mainTextArea.setText("Which organ do you want to buy?");
messageTextArea.setText(""); // Clear the message area
coinsPanel = new JPanel();
coinsPanel.setBounds(80, 100, 600, 150);
coinsPanel.setBackground(Color.black);
coinsText = new JLabel();
coinsText.setText("Coins: " + coins);
coinsText.setForeground(Color.yellow);
coinsText.setFont(normalFont);
coinsPanel.add(coinsText);
organsButtons = new JPanel();
organsButtons.setBounds(225, 350, 300, 150);
organsButtons.setBackground(Color.black);
organsButtons.setLayout(new GridLayout(5, 1));
window.add(organsButtons);
brain = choiceButton("Brain");
brain.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buyOrgan("BRAIN", mainArray, mainArrayPrice);
}
});
guts = choiceButton("Guts");
guts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buyOrgan("GUTS", mainArray, mainArrayPrice);
}
});
hands = choiceButton("Hands");
hands.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buyOrgan("HANDS", mainArray, mainArrayPrice);
}
});
heart = choiceButton("Heart");
heart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buyOrgan("HEART", mainArray, mainArrayPrice);
}
});
legs = choiceButton("Legs");
legs.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buyOrgan("LEGS", mainArray, mainArrayPrice);
}
});
organsButtons.add(brain);
organsButtons.add(guts);
organsButtons.add(hands);
organsButtons.add(heart);
organsButtons.add(legs);
window.add(coinsPanel);
if (mainArray.isEmpty()) {
organsButtons.setVisible(false);
coinsPanel.setVisible(false);
messageTextArea.setVisible(false);
mainTextArea.setText("You win! You bought \nall your organs".toUpperCase());
}
}
public void sell() {
goBackToMainPanel.setVisible(true);
if (menuPanel != null)
menuPanel.setVisible(false);
if (menuButton != null)
menuButton.setVisible(false);
mainTextPanel.setVisible(true);
mainTextArea.setText("Which organ do you want to sell?");
messageTextArea.setText(""); // Clear the message area
coinsPanel = new JPanel();
coinsPanel.setBounds(80, 100, 600, 150);
coinsPanel.setBackground(Color.black);
coinsText = new JLabel();
coinsText.setText("Coins: " + coins);
coinsText.setForeground(Color.yellow);
coinsText.setFont(normalFont);
coinsPanel.add(coinsText);
organsButtons = new JPanel();
organsButtons.setBounds(225, 350, 300, 150);
organsButtons.setBackground(Color.black);
organsButtons.setLayout(new GridLayout(5, 1));
window.add(organsButtons);
eyes = choiceButton("Eyes");
eyes.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sellOrgan("EYES", sellArray, sellArrayPrice);
}
});
lungs = choiceButton("Lungs");
lungs.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sellOrgan("LUNGS", sellArray, sellArrayPrice);
}
});
kidney = choiceButton("Kidney");
kidney.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sellOrgan("KIDNEY", sellArray, sellArrayPrice);
}
});
teeth = choiceButton("Teeth");
teeth.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sellOrgan("TEETH", sellArray, sellArrayPrice);
}
});
skin = choiceButton("Skin");
skin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sellOrgan("SKIN", sellArray, sellArrayPrice);
}
});
organsButtons.add(eyes);
organsButtons.add(lungs);
organsButtons.add(kidney);
organsButtons.add(teeth);
organsButtons.add(skin);
window.add(coinsPanel);
if (sellArray.isEmpty()) {
organsButtons.setVisible(false);
coinsPanel.setVisible(false);
messageTextArea.setVisible(false);
mainTextArea.setText("You've sold all \nyour available organs".toUpperCase());
}
}
private void buyOrgan(String organ, ArrayList<String> organsList, ArrayList<Integer> pricesList) {
int index = organsList.indexOf(organ);
if (index != -1) {
int price = pricesList.get(index);
if (coins >= price) {
coins -= price;
coinsText.setText("Coins: " + coins);
organsList.remove(index);
pricesList.remove(index);
// Inform the user
messageTextArea.setText("You've bought " + organ);
boughtOrgans.add(organ);
switch (organ) {
case "BRAIN":
brain.setForeground(Color.gray);
break;
case "GUTS":
guts.setForeground(Color.gray);
break;
case "HANDS":
hands.setForeground(Color.gray);
break;
case "HEART":
heart.setForeground(Color.gray);
break;
case "LEGS":
legs.setForeground(Color.gray);
break;
}
} else {
messageTextArea.setText("Not enough coins to buy " + organ);
}
}
if (organsList.isEmpty()) {
organsButtons.setVisible(false);
coinsPanel.setVisible(false);
messageTextArea.setVisible(false);
mainTextArea.setText("You WIN, you've bought \nall your available organs back".toUpperCase());
goBackToMainPanel.setVisible(false);
}
}
private void sellOrgan(String organ, ArrayList<String> organsList, ArrayList<Integer> pricesList) {
int index = organsList.indexOf(organ);
if (index != -1) {
int price = pricesList.get(index);
coins += price;
coinsText.setText("Coins: " + coins);
organsList.remove(index);
pricesList.remove(index);
// Inform the user
messageTextArea.setText("You've sold " + organ);
soldOrgans.add(organ);
switch (organ) {
case "EYES":
eyes.setForeground(Color.gray);
break;
case "LUNGS":
lungs.setForeground(Color.gray);
break;
case "KIDNEY":
kidney.setForeground(Color.gray);
break;
case "TEETH":
teeth.setForeground(Color.gray);
break;
case "SKIN":
skin.setForeground(Color.gray);
break;
}
}
if (organsList.isEmpty()) {
organsButtons.setVisible(false);
coinsPanel.setVisible(false);
messageTextArea.setVisible(false);
mainTextArea.setText("You've sold all \nyour available organs".toUpperCase());
}
}
public class TitleScreenHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
storyScreen();
}
}
public class ContinueButtonHandler implements ActionListener {
private int clickCount = 0;
public void actionPerformed(ActionEvent event) {
clickCount++;
if (clickCount == 1) {
mainTextArea.setText("And now you regret it?");
} else if (clickCount == 2) {
mainTextArea.setText("Fine, you can have it back");
} else if (clickCount == 3) {
mainTextArea.setText("If you can beat me in a little game of course");
} else if (clickCount == 4) {
mainMenu();
}
}
}
public class PlayHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
games();
}
}
public class BuyHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
buy();
}
}
public class SellHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
sell();
}
}
public class QuitHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
}
public class GoBackHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
mainMenu();
}
}
public class DanceWDevilHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
danceWdevil();
}
}
public class HorseRacingHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
horseRacing();
}
}
public class ElementalHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
Elemental();
}
}
}