-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexiRE-RUN
More file actions
1079 lines (953 loc) · 47 KB
/
lexiRE-RUN
File metadata and controls
1079 lines (953 loc) · 47 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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.Timer;
public class LexiGuess extends JFrame {
private static final String[] EASY_WORDS = {
"CATS","DOGS","BIRD","FISH","FROG","TREE","BOOK","CAKE","RAIN","SNOW",
"STAR","MOON","FIRE","WIND","LION","BEAR","WOLF","DEER","DUCK","FAWN",
"LAMP","DOOR","ROAD","SHIP","FARM","BELL","HILL","ROSE","LEAF","SEED"
};
private static final String[] MEDIUM_WORDS = {
"APPLE","BRAVE","CLOUD","DANCE","EARTH","FLAME","GRACE","HEART","IVORY","JELLY",
"KNEEL","LEMON","MAGIC","NIGHT","OCEAN","PLANT","QUEST","RIVER","SOLAR","TIGER",
"ULTRA","VIVID","WATER","XENON","YACHT","ZEBRA","BLAZE","CRISP","DROVE","ELITE"
};
private static final String[] HARD_WORDS = {
"BRIDGE","CASTLE","DANGER","EMBARK","FOREST","GENTLE","HEROES","IMPACT",
"JUNGLE","KNIGHT","LAUNCH","MIRROR","NARROW","OBJECT","PALACE","QUARTZ",
"RADIANT","SHADOW","TUNNEL","UNIQUE","VELVET","WONDER","YELLOW","ZIPPER",
"BLANKET","CAPTAIN","DIAMOND","ETERNAL","FREEDOM","GRANITE"
};
private static final Color BG_DARK = new Color(8, 10, 18);
private static final Color BG_PANEL = new Color(14, 17, 28);
private static final Color GOLD = new Color(212, 175, 95);
private static final Color GOLD_LIGHT = new Color(240, 210, 130);
private static final Color GOLD_DIM = new Color(140, 110, 50);
private static final Color SILVER = new Color(180, 185, 200);
private static final Color TEXT_WHITE = new Color(235, 232, 225);
private static final Color TEXT_MUTED = new Color(120, 118, 130);
private static final Color TILE_EMPTY_BG = new Color(22, 26, 42);
private static final Color TILE_EMPTY_BD = new Color(55, 55, 75);
private static final Color GREEN_CORRECT = new Color(60, 140, 90);
private static final Color YELLOW_PRESENT = new Color(190, 155, 40);
private static final Color GRAY_ABSENT = new Color(45, 45, 58);
private static final Color RED_DANGER = new Color(180, 60, 60);
private static final Color EASY_CLR = new Color(70, 170, 100);
private static final Color MEDIUM_CLR = new Color(190, 155, 40);
private static final Color HARD_CLR = new Color(180, 70, 70);
private String targetWord = "";
private String difficulty = "EASY";
private int maxAttempts = 6;
private int currentAttempt = 0;
private int score = 0;
private int sessionScore = 0;
private int currentStage = 1;
private boolean gameOver = false;
private boolean gameWon = false;
private List<String> guesses = new ArrayList<>();
private List<int[]> feedbackList = new ArrayList<>();
private Set<Character> correctLetters = new HashSet<>();
private Set<Character> presentLetters = new HashSet<>();
private Set<Character> absentLetters = new HashSet<>();
private int wordLength;
private List<LeaderboardEntry> leaderboard = new ArrayList<>();
private String currentPlayerName = "Player";
private CardLayout cardLayout;
private JPanel cardPanel;
private JLabel[][] tiles;
private JPanel gridPanel;
private HangmanPanel hangmanPanel;
private JTextField inputField;
private JButton submitBtn;
private JLabel messageLabel;
private JLabel difficultyLabel;
private JLabel inGameScoreLabel;
private JLabel sessionScoreLabel;
private JLabel stageLabel;
private Map<Character, JLabel> keyLabels = new HashMap<>();
private JPanel keyboardPanel;
private JPanel leaderboardListPanel;
public LexiGuess() {
setTitle("LexiGuess - Vocabulary Enhancement Game");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
getContentPane().setBackground(BG_DARK);
cardLayout = new CardLayout();
cardPanel = new JPanel(cardLayout);
cardPanel.setBackground(BG_DARK);
cardPanel.add(buildStartScreen(), "START");
cardPanel.add(buildMenuScreen(), "MENU");
cardPanel.add(buildGameScreen(), "GAME");
cardPanel.add(buildInstructionsScreen(), "INSTRUCTIONS");
cardPanel.add(buildLeaderboardScreen(), "LEADERBOARD");
add(cardPanel);
setSize(960, 780);
setLocationRelativeTo(null);
setVisible(true);
cardLayout.show(cardPanel, "START");
}
static class GradientPanel extends JPanel {
private Color top, bottom;
GradientPanel(Color top, Color bottom) {
this.top = top;
this.bottom = bottom;
setOpaque(false);
}
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(new GradientPaint(0, 0, top, 0, getHeight(), bottom));
g2.fillRect(0, 0, getWidth(), getHeight());
super.paintComponent(g);
}
}
private JLabel makeOrnamentLabel(String text) {
JLabel lbl = new JLabel(text, SwingConstants.CENTER);
lbl.setFont(new Font("Serif", Font.PLAIN, 14));
lbl.setForeground(GOLD_DIM);
lbl.setAlignmentX(CENTER_ALIGNMENT);
return lbl;
}
private JButton makeFancyButton(String text, Color bgColor, Color borderColor) {
JButton btn = new JButton(text) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(bgColor);
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
super.paintComponent(g);
}
};
btn.setFont(new Font("Serif", Font.BOLD, 13));
btn.setForeground(TEXT_WHITE);
btn.setContentAreaFilled(false);
btn.setBorderPainted(false);
btn.setFocusPainted(false);
btn.setOpaque(false);
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btn.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(borderColor, 1),
BorderFactory.createEmptyBorder(6, 16, 6, 16)
));
return btn;
}
private JButton makeLinkButton(String text) {
JButton btn = new JButton(text);
btn.setFont(new Font("Serif", Font.PLAIN, 13));
btn.setForeground(GOLD_DIM);
btn.setContentAreaFilled(false);
btn.setBorderPainted(false);
btn.setFocusPainted(false);
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btn.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) { btn.setForeground(GOLD); }
public void mouseExited(MouseEvent e) { btn.setForeground(GOLD_DIM); }
});
return btn;
}
private JPanel buildStartScreen() {
JPanel root = new GradientPanel(BG_DARK, new Color(12, 15, 28));
root.setLayout(new BorderLayout());
JPanel center = new JPanel();
center.setOpaque(false);
center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
center.setBorder(BorderFactory.createEmptyBorder(100, 80, 100, 80));
center.add(makeOrnamentLabel("--- * ---"));
center.add(Box.createVerticalStrut(20));
JLabel title = new JLabel("LexiGuess", SwingConstants.CENTER);
title.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 72));
title.setForeground(GOLD);
title.setAlignmentX(CENTER_ALIGNMENT);
center.add(title);
JLabel sub = new JLabel("--- Vocabulary Enhancement Game ---", SwingConstants.CENTER);
sub.setFont(new Font("Serif", Font.ITALIC, 18));
sub.setForeground(GOLD_DIM);
sub.setAlignmentX(CENTER_ALIGNMENT);
center.add(sub);
center.add(Box.createVerticalStrut(40));
center.add(makeOrnamentLabel("* o *"));
center.add(Box.createVerticalStrut(50));
JLabel nameLbl = new JLabel("Enter Your Name:", SwingConstants.CENTER);
nameLbl.setFont(new Font("Serif", Font.BOLD, 18));
nameLbl.setForeground(TEXT_WHITE);
nameLbl.setAlignmentX(CENTER_ALIGNMENT);
center.add(nameLbl);
center.add(Box.createVerticalStrut(10));
JTextField nameField = new JTextField("Player", 15);
nameField.setFont(new Font("Serif", Font.PLAIN, 18));
nameField.setForeground(TEXT_WHITE);
nameField.setBackground(new Color(22, 26, 42));
nameField.setCaretColor(GOLD);
nameField.setHorizontalAlignment(SwingConstants.CENTER);
nameField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(GOLD_DIM, 1),
BorderFactory.createEmptyBorder(8, 15, 8, 15)
));
nameField.setMaximumSize(new Dimension(250, 45));
nameField.setAlignmentX(CENTER_ALIGNMENT);
center.add(nameField);
center.add(Box.createVerticalStrut(40));
JButton startBtn = new JButton("START GAME") {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
GradientPaint gp = new GradientPaint(0, 0, GOLD, 0, getHeight(), GOLD_DIM);
g2.setPaint(gp);
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 12, 12);
super.paintComponent(g);
}
};
startBtn.setFont(new Font("Serif", Font.BOLD, 24));
startBtn.setForeground(BG_DARK);
startBtn.setContentAreaFilled(false);
startBtn.setBorderPainted(false);
startBtn.setFocusPainted(false);
startBtn.setOpaque(false);
startBtn.setPreferredSize(new Dimension(250, 60));
startBtn.setMaximumSize(new Dimension(250, 60));
startBtn.setAlignmentX(CENTER_ALIGNMENT);
startBtn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
startBtn.addActionListener(e -> {
String name = nameField.getText().trim();
if (!name.isEmpty()) currentPlayerName = name;
cardLayout.show(cardPanel, "MENU");
});
startBtn.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) { startBtn.setForeground(TEXT_WHITE); }
public void mouseExited(MouseEvent e) { startBtn.setForeground(BG_DARK); }
});
center.add(startBtn);
center.add(Box.createVerticalStrut(30));
JButton leaderBtn = makeFancyButton("View Leaderboard", new Color(25, 22, 12), GOLD_DIM);
leaderBtn.setAlignmentX(CENTER_ALIGNMENT);
leaderBtn.addActionListener(e -> {
updateLeaderboardDisplay();
cardLayout.show(cardPanel, "LEADERBOARD");
});
center.add(leaderBtn);
root.add(center, BorderLayout.CENTER);
JLabel bottomOrnament = new JLabel("* o *", SwingConstants.CENTER);
bottomOrnament.setFont(new Font("Serif", Font.PLAIN, 14));
bottomOrnament.setForeground(GOLD_DIM);
bottomOrnament.setBorder(BorderFactory.createEmptyBorder(0, 0, 30, 0));
root.add(bottomOrnament, BorderLayout.SOUTH);
return root;
}
private JPanel buildMenuScreen() {
JPanel root = new GradientPanel(BG_DARK, new Color(12, 15, 28));
root.setLayout(new BorderLayout());
JPanel topBar = new JPanel(new FlowLayout(FlowLayout.RIGHT, 20, 12));
topBar.setOpaque(false);
JButton instrBtn = makeLinkButton("How to Play");
instrBtn.addActionListener(e -> cardLayout.show(cardPanel, "INSTRUCTIONS"));
JButton leaderBtn = makeLinkButton("Leaderboard");
leaderBtn.addActionListener(e -> {
updateLeaderboardDisplay();
cardLayout.show(cardPanel, "LEADERBOARD");
});
JButton exitBtn = makeLinkButton("Exit");
exitBtn.addActionListener(e -> System.exit(0));
topBar.add(instrBtn);
topBar.add(leaderBtn);
topBar.add(exitBtn);
root.add(topBar, BorderLayout.NORTH);
JPanel center = new JPanel();
center.setOpaque(false);
center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
center.setBorder(BorderFactory.createEmptyBorder(10, 80, 20, 80));
center.add(makeOrnamentLabel("--- * ---"));
center.add(Box.createVerticalStrut(10));
JLabel title = new JLabel("LexiGuess", SwingConstants.CENTER);
title.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 58));
title.setForeground(GOLD);
title.setAlignmentX(CENTER_ALIGNMENT);
center.add(title);
JLabel sub = new JLabel("--- Vocabulary Enhancement Game ---", SwingConstants.CENTER);
sub.setFont(new Font("Serif", Font.ITALIC, 15));
sub.setForeground(GOLD_DIM);
sub.setAlignmentX(CENTER_ALIGNMENT);
center.add(sub);
center.add(Box.createVerticalStrut(8));
center.add(makeOrnamentLabel("* o *"));
center.add(Box.createVerticalStrut(28));
JLabel chooseLbl = new JLabel("Choose Your Challenge", SwingConstants.CENTER);
chooseLbl.setFont(new Font("Serif", Font.BOLD, 22));
chooseLbl.setForeground(TEXT_WHITE);
chooseLbl.setAlignmentX(CENTER_ALIGNMENT);
center.add(chooseLbl);
center.add(Box.createVerticalStrut(20));
JPanel diffRow = new JPanel(new FlowLayout(FlowLayout.CENTER, 22, 0));
diffRow.setOpaque(false);
diffRow.add(makeDiffCard("EASY", "Novice", "4-letter words", "6 attempts", EASY_CLR, "*"));
diffRow.add(makeDiffCard("MEDIUM", "Scholar", "5-letter words", "6 attempts", MEDIUM_CLR, "**"));
diffRow.add(makeDiffCard("HARD", "Mastermind", "6+ letter words","6 attempts", HARD_CLR, "***"));
center.add(diffRow);
center.add(Box.createVerticalStrut(30));
sessionScoreLabel = new JLabel("Session Score: 0 | Stage: 1", SwingConstants.CENTER);
sessionScoreLabel.setFont(new Font("Serif", Font.BOLD, 16));
sessionScoreLabel.setForeground(GOLD);
sessionScoreLabel.setAlignmentX(CENTER_ALIGNMENT);
center.add(sessionScoreLabel);
root.add(center, BorderLayout.CENTER);
JLabel bottomOrnament = new JLabel("* o *", SwingConstants.CENTER);
bottomOrnament.setFont(new Font("Serif", Font.PLAIN, 14));
bottomOrnament.setForeground(GOLD_DIM);
bottomOrnament.setBorder(BorderFactory.createEmptyBorder(0, 0, 16, 0));
root.add(bottomOrnament, BorderLayout.SOUTH);
return root;
}
private JPanel makeDiffCard(String diff, String rankTitle, String wordInfo, String attempts, Color accent, String stars) {
JPanel card = new JPanel() {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
GradientPaint bg = new GradientPaint(0, 0,
new Color(accent.getRed()/7, accent.getGreen()/7, accent.getBlue()/7),
0, getHeight(),
new Color(accent.getRed()/11, accent.getGreen()/11, accent.getBlue()/11));
g2.setPaint(bg);
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 16, 16);
g2.setColor(accent);
g2.setStroke(new BasicStroke(1.5f));
g2.drawRoundRect(1, 1, getWidth()-3, getHeight()-3, 15, 15);
g2.setColor(new Color(255,255,255,12));
g2.setStroke(new BasicStroke(1f));
g2.drawRoundRect(4, 4, getWidth()-9, getHeight()-9, 12, 12);
}
};
card.setLayout(new BoxLayout(card, BoxLayout.Y_AXIS));
card.setPreferredSize(new Dimension(208, 210));
card.setOpaque(false);
card.setBorder(BorderFactory.createEmptyBorder(18, 16, 18, 16));
card.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
JLabel starsLbl = new JLabel(stars, SwingConstants.CENTER);
starsLbl.setFont(new Font("Serif", Font.PLAIN, 13));
starsLbl.setForeground(accent);
starsLbl.setAlignmentX(CENTER_ALIGNMENT);
JLabel titleLbl = new JLabel(diff, SwingConstants.CENTER);
titleLbl.setFont(new Font("Serif", Font.BOLD, 24));
titleLbl.setForeground(accent);
titleLbl.setAlignmentX(CENTER_ALIGNMENT);
JLabel rankLbl = new JLabel(rankTitle, SwingConstants.CENTER);
rankLbl.setFont(new Font("Serif", Font.ITALIC, 13));
rankLbl.setForeground(SILVER);
rankLbl.setAlignmentX(CENTER_ALIGNMENT);
JPanel sepLine = new JPanel() {
@Override protected void paintComponent(Graphics g) {
g.setColor(new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 80));
g.drawLine(10,0,getWidth()-10,0);
}
};
sepLine.setOpaque(false);
sepLine.setPreferredSize(new Dimension(160, 4));
sepLine.setMaximumSize(new Dimension(160, 4));
sepLine.setAlignmentX(CENTER_ALIGNMENT);
JLabel wordLbl = new JLabel(wordInfo, SwingConstants.CENTER);
wordLbl.setFont(new Font("SansSerif", Font.PLAIN, 12));
wordLbl.setForeground(TEXT_MUTED);
wordLbl.setAlignmentX(CENTER_ALIGNMENT);
JLabel attLbl = new JLabel(attempts, SwingConstants.CENTER);
attLbl.setFont(new Font("SansSerif", Font.PLAIN, 12));
attLbl.setForeground(TEXT_MUTED);
attLbl.setAlignmentX(CENTER_ALIGNMENT);
JButton playBtn = new JButton("Play ->") {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(accent);
g2.fillRoundRect(0,0,getWidth(),getHeight(),8,8);
super.paintComponent(g);
}
};
playBtn.setFont(new Font("Serif", Font.BOLD, 13));
playBtn.setForeground(BG_DARK);
playBtn.setContentAreaFilled(false);
playBtn.setBorderPainted(false);
playBtn.setFocusPainted(false);
playBtn.setOpaque(false);
playBtn.setMaximumSize(new Dimension(140, 32));
playBtn.setAlignmentX(CENTER_ALIGNMENT);
playBtn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
playBtn.addActionListener(e -> { difficulty = diff; startGame(); });
card.add(starsLbl);
card.add(Box.createVerticalStrut(4));
card.add(titleLbl);
card.add(rankLbl);
card.add(Box.createVerticalStrut(8));
card.add(sepLine);
card.add(Box.createVerticalStrut(8));
card.add(wordLbl);
card.add(attLbl);
card.add(Box.createVerticalGlue());
card.add(playBtn);
card.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
card.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(accent, 2),
BorderFactory.createEmptyBorder(17,15,17,15)));
card.repaint();
}
public void mouseExited(MouseEvent e) {
card.setBorder(BorderFactory.createEmptyBorder(18,16,18,16));
card.repaint();
}
});
return card;
}
private JPanel buildInstructionsScreen() {
JPanel root = new GradientPanel(BG_DARK, new Color(12, 15, 28));
root.setLayout(new BorderLayout(0, 0));
root.setBorder(BorderFactory.createEmptyBorder(30, 70, 30, 70));
JLabel title = new JLabel("How to Play", SwingConstants.CENTER);
title.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 36));
title.setForeground(GOLD);
title.setBorder(BorderFactory.createEmptyBorder(0,0,18,0));
root.add(title, BorderLayout.NORTH);
String html = "<html><body style='background:#0e1118;color:#ebe8e1;font-family:Serif;padding:20px;'>"
+ "<h2 style='color:#d4af5f;'>Objective</h2>"
+ "<p>Decipher the hidden word within 6 attempts to claim victory and advance to the next stage.</p>"
+ "<hr style='border-color:#8c6e32;'>"
+ "<h2 style='color:#d4af5f;'>Stages System</h2>"
+ "<p>Each correct guess advances you to the next stage. Failing a word resets your score to 0 but keeps your stage progress.</p>"
+ "<hr style='border-color:#8c6e32;'>"
+ "<h2 style='color:#d4af5f;'>Colour Feedback</h2>"
+ "<table border='0' cellpadding='6'>"
+ "<tr><td style='background:#3c8c5a;color:white;padding:4px 12px;'><b>GREEN</b></td><td>Correct letter in the correct position</td></tr>"
+ "<tr><td style='background:#be9b28;color:white;padding:4px 12px;'><b>AMBER</b></td><td>Letter exists in the word but wrong position</td></tr>"
+ "<tr><td style='background:#2d2d3a;color:#ccc;padding:4px 12px;'><b>GREY</b></td><td>Letter is not in the word at all</td></tr>"
+ "</table>"
+ "<hr style='border-color:#8c6e32;'>"
+ "<h2 style='color:#d4af5f;'>Difficulty Levels</h2>"
+ "<table border='0' cellpadding='6'>"
+ "<tr><td style='color:#46aa64;'><b>Easy</b></td><td>4-letter words</td></tr>"
+ "<tr><td style='color:#be9b28;'><b>Medium</b></td><td>5-letter words</td></tr>"
+ "<tr><td style='color:#b44646;'><b>Hard</b></td><td>6 or more letter words</td></tr>"
+ "</table>"
+ "<hr style='border-color:#8c6e32;'>"
+ "<h2 style='color:#d4af5f;'>The Gallows</h2>"
+ "<p>Each wrong guess adds a body part. After 6 wrong guesses, the figure is complete and the game ends in defeat.</p>"
+ "<hr style='border-color:#8c6e32;'>"
+ "<h2 style='color:#d4af5f;'>Scoring</h2>"
+ "<table border='0' cellpadding='6'>"
+ "<tr><td style='color:#46aa64;'><b>Easy</b></td><td>100 pts base + 10 x remaining attempts</td></tr>"
+ "<tr><td style='color:#be9b28;'><b>Medium</b></td><td>200 pts base + 20 x remaining attempts</td></tr>"
+ "<tr><td style='color:#b44646;'><b>Hard</b></td><td>300 pts base + 30 x remaining attempts</td></tr>"
+ "</table>"
+ "</body></html>";
JEditorPane ep = new JEditorPane("text/html", html);
ep.setEditable(false);
ep.setBackground(new Color(14, 17, 24));
JScrollPane scroll = new JScrollPane(ep);
scroll.setBorder(BorderFactory.createLineBorder(GOLD_DIM, 1));
scroll.getViewport().setBackground(new Color(14, 17, 24));
root.add(scroll, BorderLayout.CENTER);
JButton back = makeFancyButton("<- Return to Hall", new Color(25,20,10), GOLD_DIM);
back.addActionListener(e -> cardLayout.show(cardPanel, "MENU"));
JPanel bot = new JPanel(new FlowLayout(FlowLayout.CENTER));
bot.setOpaque(false);
bot.setBorder(BorderFactory.createEmptyBorder(16,0,0,0));
bot.add(back);
root.add(bot, BorderLayout.SOUTH);
return root;
}
private JPanel buildLeaderboardScreen() {
JPanel root = new GradientPanel(BG_DARK, new Color(12, 15, 28));
root.setLayout(new BorderLayout(0, 0));
root.setBorder(BorderFactory.createEmptyBorder(30, 70, 30, 70));
JLabel title = new JLabel("* Leaderboard *", SwingConstants.CENTER);
title.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 36));
title.setForeground(GOLD);
title.setBorder(BorderFactory.createEmptyBorder(0, 0, 18, 0));
root.add(title, BorderLayout.NORTH);
leaderboardListPanel = new JPanel();
leaderboardListPanel.setLayout(new BoxLayout(leaderboardListPanel, BoxLayout.Y_AXIS));
leaderboardListPanel.setOpaque(false);
leaderboardListPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
JScrollPane scroll = new JScrollPane(leaderboardListPanel);
scroll.setBorder(BorderFactory.createLineBorder(GOLD_DIM, 1));
scroll.getViewport().setBackground(new Color(14, 17, 24));
scroll.setOpaque(false);
root.add(scroll, BorderLayout.CENTER);
JPanel bot = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 0));
bot.setOpaque(false);
bot.setBorder(BorderFactory.createEmptyBorder(16, 0, 0, 0));
JButton backBtn = makeFancyButton("<- Return", new Color(25, 20, 10), GOLD_DIM);
backBtn.addActionListener(e -> cardLayout.show(cardPanel, "MENU"));
JButton clearBtn = makeFancyButton("Clear Leaderboard", new Color(50, 20, 20), RED_DANGER);
clearBtn.addActionListener(e -> {
leaderboard.clear();
updateLeaderboardDisplay();
});
bot.add(backBtn);
bot.add(clearBtn);
root.add(bot, BorderLayout.SOUTH);
return root;
}
private void updateLeaderboardDisplay() {
leaderboardListPanel.removeAll();
leaderboard.sort((a, b) -> Integer.compare(b.score, a.score));
if (leaderboard.isEmpty()) {
JLabel emptyLbl = new JLabel("No entries yet. Play to get on the board!", SwingConstants.CENTER);
emptyLbl.setFont(new Font("Serif", Font.ITALIC, 16));
emptyLbl.setForeground(TEXT_MUTED);
emptyLbl.setAlignmentX(CENTER_ALIGNMENT);
leaderboardListPanel.add(Box.createVerticalStrut(50));
leaderboardListPanel.add(emptyLbl);
} else {
JPanel header = new JPanel(new GridLayout(1, 4, 10, 0));
header.setOpaque(false);
header.setMaximumSize(new Dimension(600, 35));
header.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, GOLD_DIM));
String[] headers = {"Rank", "Player", "Score", "Stage"};
for (String h : headers) {
JLabel lbl = new JLabel(h, SwingConstants.CENTER);
lbl.setFont(new Font("Serif", Font.BOLD, 14));
lbl.setForeground(GOLD);
header.add(lbl);
}
leaderboardListPanel.add(header);
leaderboardListPanel.add(Box.createVerticalStrut(5));
int rank = 1;
for (LeaderboardEntry entry : leaderboard) {
if (rank > 10) break;
JPanel row = new JPanel(new GridLayout(1, 4, 10, 0));
row.setOpaque(false);
row.setMaximumSize(new Dimension(600, 35));
row.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(50, 50, 60)));
Color rowColor = rank == 1 ? GOLD : rank == 2 ? SILVER : rank == 3 ? new Color(205, 127, 50) : TEXT_WHITE;
JLabel rankLbl = new JLabel("#" + rank, SwingConstants.CENTER);
rankLbl.setFont(new Font("Serif", Font.BOLD, 14));
rankLbl.setForeground(rowColor);
JLabel nameLbl = new JLabel(entry.name, SwingConstants.CENTER);
nameLbl.setFont(new Font("Serif", Font.PLAIN, 14));
nameLbl.setForeground(rowColor);
JLabel scoreLbl = new JLabel(String.valueOf(entry.score), SwingConstants.CENTER);
scoreLbl.setFont(new Font("Serif", Font.BOLD, 14));
scoreLbl.setForeground(rowColor);
JLabel stageLbl = new JLabel(String.valueOf(entry.stage), SwingConstants.CENTER);
stageLbl.setFont(new Font("Serif", Font.PLAIN, 14));
stageLbl.setForeground(rowColor);
row.add(rankLbl);
row.add(nameLbl);
row.add(scoreLbl);
row.add(stageLbl);
leaderboardListPanel.add(row);
leaderboardListPanel.add(Box.createVerticalStrut(3));
rank++;
}
}
leaderboardListPanel.revalidate();
leaderboardListPanel.repaint();
}
private JPanel buildGameScreen() {
JPanel root = new GradientPanel(BG_DARK, new Color(10, 13, 22));
root.setLayout(new BorderLayout(0, 0));
JPanel topBar = new JPanel(new BorderLayout());
topBar.setOpaque(false);
topBar.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,0,1,0, GOLD_DIM),
BorderFactory.createEmptyBorder(10,18,10,18)
));
JButton backBtn = makeFancyButton("<- Back", new Color(25,22,12), GOLD_DIM);
backBtn.addActionListener(e -> {
sessionScoreLabel.setText("Session Score: " + sessionScore + " | Stage: " + currentStage);
cardLayout.show(cardPanel, "MENU");
});
topBar.add(backBtn, BorderLayout.WEST);
JPanel titleGroup = new JPanel();
titleGroup.setOpaque(false);
titleGroup.setLayout(new BoxLayout(titleGroup, BoxLayout.Y_AXIS));
JLabel gTitle = new JLabel("LexiGuess", SwingConstants.CENTER);
gTitle.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 26));
gTitle.setForeground(GOLD);
gTitle.setAlignmentX(CENTER_ALIGNMENT);
difficultyLabel = new JLabel("", SwingConstants.CENTER);
difficultyLabel.setFont(new Font("Serif", Font.ITALIC, 12));
difficultyLabel.setForeground(GOLD_DIM);
difficultyLabel.setAlignmentX(CENTER_ALIGNMENT);
titleGroup.add(gTitle);
titleGroup.add(difficultyLabel);
topBar.add(titleGroup, BorderLayout.CENTER);
JPanel scorePanel = new JPanel();
scorePanel.setOpaque(false);
scorePanel.setLayout(new BoxLayout(scorePanel, BoxLayout.Y_AXIS));
inGameScoreLabel = new JLabel("Score: 0", SwingConstants.RIGHT);
inGameScoreLabel.setFont(new Font("Serif", Font.BOLD, 15));
inGameScoreLabel.setForeground(GOLD);
inGameScoreLabel.setAlignmentX(RIGHT_ALIGNMENT);
stageLabel = new JLabel("Stage: 1", SwingConstants.RIGHT);
stageLabel.setFont(new Font("Serif", Font.ITALIC, 12));
stageLabel.setForeground(GOLD_DIM);
stageLabel.setAlignmentX(RIGHT_ALIGNMENT);
scorePanel.add(inGameScoreLabel);
scorePanel.add(stageLabel);
topBar.add(scorePanel, BorderLayout.EAST);
root.add(topBar, BorderLayout.NORTH);
JPanel center = new JPanel(new GridBagLayout());
center.setOpaque(false);
center.setBorder(BorderFactory.createEmptyBorder(14,20,10,20));
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 18, 0, 18);
gbc.anchor = GridBagConstraints.NORTH;
hangmanPanel = new HangmanPanel();
hangmanPanel.setPreferredSize(new Dimension(215, 295));
gbc.gridx = 0; gbc.gridy = 0;
center.add(hangmanPanel, gbc);
gridPanel = new JPanel();
gridPanel.setOpaque(false);
gbc.gridx = 1; gbc.gridy = 0;
center.add(gridPanel, gbc);
root.add(center, BorderLayout.CENTER);
JPanel bottom = new JPanel();
bottom.setOpaque(false);
bottom.setLayout(new BoxLayout(bottom, BoxLayout.Y_AXIS));
bottom.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(1,0,0,0, GOLD_DIM),
BorderFactory.createEmptyBorder(12,20,14,20)
));
messageLabel = new JLabel(" ", SwingConstants.CENTER);
messageLabel.setFont(new Font("Serif", Font.ITALIC, 15));
messageLabel.setForeground(TEXT_WHITE);
messageLabel.setAlignmentX(CENTER_ALIGNMENT);
bottom.add(messageLabel);
bottom.add(Box.createVerticalStrut(8));
JPanel inputRow = new JPanel(new FlowLayout(FlowLayout.CENTER, 12, 0));
inputRow.setOpaque(false);
inputField = new JTextField(10) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(20, 24, 38));
g2.fillRoundRect(0,0,getWidth(),getHeight(),8,8);
super.paintComponent(g);
}
};
inputField.setFont(new Font("Monospaced", Font.BOLD, 20));
inputField.setForeground(TEXT_WHITE);
inputField.setBackground(new Color(0,0,0,0));
inputField.setOpaque(false);
inputField.setCaretColor(GOLD);
inputField.setHorizontalAlignment(SwingConstants.CENTER);
inputField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(GOLD_DIM, 1),
BorderFactory.createEmptyBorder(6,10,6,10)
));
inputField.setPreferredSize(new Dimension(210, 44));
inputField.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (!Character.isLetter(c)) { e.consume(); return; }
if (inputField.getText().length() >= wordLength) e.consume();
else e.setKeyChar(Character.toUpperCase(c));
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) submitGuess();
}
});
submitBtn = makeFancyButton("Guess ->", new Color(20,40,20), EASY_CLR);
submitBtn.addActionListener(e -> submitGuess());
submitBtn.setPreferredSize(new Dimension(120, 44));
JButton newWordBtn = makeFancyButton("New Word", new Color(35,30,15), GOLD_DIM);
newWordBtn.addActionListener(e -> startGame());
newWordBtn.setPreferredSize(new Dimension(110, 44));
inputRow.add(inputField);
inputRow.add(submitBtn);
inputRow.add(newWordBtn);
bottom.add(inputRow);
bottom.add(Box.createVerticalStrut(10));
keyboardPanel = new JPanel();
keyboardPanel.setOpaque(false);
buildKeyboard();
bottom.add(keyboardPanel);
root.add(bottom, BorderLayout.SOUTH);
return root;
}
private void buildKeyboard() {
keyboardPanel.removeAll();
keyboardPanel.setLayout(new BoxLayout(keyboardPanel, BoxLayout.Y_AXIS));
keyLabels.clear();
String[] rows = {"QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM"};
for (String row : rows) {
JPanel rowP = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 2));
rowP.setOpaque(false);
for (char ch : row.toCharArray()) {
JLabel k = new JLabel(String.valueOf(ch), SwingConstants.CENTER) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(getBackground());
g2.fillRoundRect(0,0,getWidth(),getHeight(),6,6);
super.paintComponent(g);
}
};
k.setFont(new Font("SansSerif", Font.BOLD, 11));
k.setForeground(TEXT_WHITE);
k.setBackground(new Color(30, 34, 50));
k.setOpaque(false);
k.setPreferredSize(new Dimension(30, 30));
k.setBorder(BorderFactory.createLineBorder(new Color(55,55,75), 1));
keyLabels.put(ch, k);
rowP.add(k);
}
keyboardPanel.add(rowP);
}
}
private void updateKeyboard() {
for (Map.Entry<Character, JLabel> e : keyLabels.entrySet()) {
char ch = e.getKey(); JLabel lbl = e.getValue();
if (correctLetters.contains(ch)) { lbl.setBackground(GREEN_CORRECT); lbl.setBorder(BorderFactory.createLineBorder(GREEN_CORRECT.brighter(),1)); }
else if (presentLetters.contains(ch)) { lbl.setBackground(YELLOW_PRESENT); lbl.setBorder(BorderFactory.createLineBorder(YELLOW_PRESENT.brighter(),1)); }
else if (absentLetters.contains(ch)) { lbl.setBackground(GRAY_ABSENT); lbl.setForeground(TEXT_MUTED); }
}
keyboardPanel.repaint();
}
private void startGame() {
String[] bank = difficulty.equals("EASY") ? EASY_WORDS : difficulty.equals("MEDIUM") ? MEDIUM_WORDS : HARD_WORDS;
targetWord = bank[new Random().nextInt(bank.length)];
wordLength = targetWord.length();
guesses.clear(); feedbackList.clear();
correctLetters.clear(); presentLetters.clear(); absentLetters.clear();
currentAttempt = 0; score = 0; gameOver = false; gameWon = false;
buildGrid();
buildKeyboard();
hangmanPanel.resetAnimation();
hangmanPanel.repaint();
Color dc = difficulty.equals("EASY") ? EASY_CLR : difficulty.equals("MEDIUM") ? MEDIUM_CLR : HARD_CLR;
difficultyLabel.setForeground(dc);
difficultyLabel.setText(difficulty + " | " + wordLength + "-letter word");
messageLabel.setText("Decipher the hidden " + wordLength + "-letter word...");
messageLabel.setForeground(TEXT_MUTED);
inGameScoreLabel.setText("Score: " + sessionScore);
stageLabel.setText("Stage: " + currentStage);
inputField.setText("");
inputField.setEnabled(true);
submitBtn.setEnabled(true);
cardLayout.show(cardPanel, "GAME");
inputField.requestFocus();
}
private void buildGrid() {
gridPanel.removeAll();
int tileSize = wordLength <= 5 ? 60 : wordLength == 6 ? 54 : 48;
gridPanel.setLayout(new GridLayout(maxAttempts, wordLength, 6, 6));
tiles = new JLabel[maxAttempts][wordLength];
for (int r = 0; r < maxAttempts; r++) {
for (int c = 0; c < wordLength; c++) {
JLabel tile = new JLabel("", SwingConstants.CENTER) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(getBackground());
g2.fillRoundRect(0,0,getWidth(),getHeight(),10,10);
g2.setColor(new Color(255,255,255,14));
g2.setStroke(new BasicStroke(1f));
g2.drawRoundRect(1,1,getWidth()-3,getHeight()-3,9,9);
super.paintComponent(g);
}
};
tile.setFont(new Font("Serif", Font.BOLD, tileSize - 22));
tile.setForeground(TEXT_WHITE);
tile.setBackground(TILE_EMPTY_BG);
tile.setOpaque(false);
tile.setBorder(BorderFactory.createLineBorder(TILE_EMPTY_BD, 1));
tile.setPreferredSize(new Dimension(tileSize, tileSize));
tiles[r][c] = tile;
gridPanel.add(tile);
}
}
gridPanel.revalidate();
gridPanel.repaint();
}
private void submitGuess() {
if (gameOver || gameWon) return;
String guess = inputField.getText().trim().toUpperCase();
if (guess.length() != wordLength) {
messageLabel.setText("Word must be exactly " + wordLength + " letters!");
messageLabel.setForeground(MEDIUM_CLR);
return;
}
int[] fb = computeFeedback(guess, targetWord);
guesses.add(guess); feedbackList.add(fb);
for (int c = 0; c < wordLength; c++) {
JLabel tile = tiles[currentAttempt][c];
tile.setText(String.valueOf(guess.charAt(c)));
tile.setBorder(null);
if (fb[c]==2) { tile.setBackground(GREEN_CORRECT); correctLetters.add(guess.charAt(c)); }
else if (fb[c]==1) { tile.setBackground(YELLOW_PRESENT); presentLetters.add(guess.charAt(c)); }
else { tile.setBackground(GRAY_ABSENT); absentLetters.add(guess.charAt(c)); }
tile.repaint();
}
currentAttempt++;
updateKeyboard();
boolean allCorrect = true;
for (int f : fb) if (f != 2) { allCorrect = false; break; }
if (!allCorrect) {
hangmanPanel.triggerDropAnimation(countWrongGuesses());
} else {
hangmanPanel.repaint();
}
if (allCorrect) {
gameWon = true;
int remaining = maxAttempts - currentAttempt;
int base = difficulty.equals("EASY") ? 100 : difficulty.equals("MEDIUM") ? 200 : 300;
int bonus = difficulty.equals("EASY") ? 10 : difficulty.equals("MEDIUM") ? 20 : 30;
int roundScore = base + remaining * bonus;
sessionScore += roundScore;
currentStage++;
messageLabel.setText("Magnificent! The word was " + targetWord + " | +" + roundScore + " pts");
messageLabel.setForeground(GOLD);
inGameScoreLabel.setText("Score: " + sessionScore);
stageLabel.setText("Stage: " + currentStage);
sessionScoreLabel.setText("Session Score: " + sessionScore + " | Stage: " + currentStage);
inputField.setEnabled(false); submitBtn.setEnabled(false);
addToLeaderboard(currentPlayerName, sessionScore, currentStage);
} else if (currentAttempt >= maxAttempts) {
gameOver = true;
messageLabel.setText("The word was: " + targetWord + " -- Score reset!");
messageLabel.setForeground(RED_DANGER);
if (sessionScore > 0) addToLeaderboard(currentPlayerName, sessionScore, currentStage);
sessionScore = 0;
inGameScoreLabel.setText("Score: 0");
sessionScoreLabel.setText("Session Score: 0 | Stage: " + currentStage);
inputField.setEnabled(false); submitBtn.setEnabled(false);
} else {
int left = maxAttempts - currentAttempt;
messageLabel.setText("Attempt " + currentAttempt + " of " + maxAttempts + " | " + left + " remaining");
messageLabel.setForeground(TEXT_MUTED);
}
inputField.setText("");
gridPanel.repaint();
}
private int countWrongGuesses() {
int wrongs = 0;
for (int[] fb : feedbackList) {
boolean allC = true;
for (int f : fb) if (f != 2) { allC = false; break; }
if (!allC) wrongs++;
}
return wrongs;
}
private void addToLeaderboard(String name, int score, int stage) {
boolean found = false;
for (LeaderboardEntry entry : leaderboard) {
if (entry.name.equals(name)) {
if (score > entry.score) { entry.score = score; entry.stage = stage; }
found = true; break;
}
}
if (!found) leaderboard.add(new LeaderboardEntry(name, score, stage));
}
private int[] computeFeedback(String guess, String target) {
int len = target.length();
int[] result = new int[len];
boolean[] tUsed = new boolean[len], gUsed = new boolean[len];
for (int i=0;i<len;i++) if (guess.charAt(i)==target.charAt(i)) { result[i]=2; tUsed[i]=gUsed[i]=true; }
for (int i=0;i<len;i++) { if (gUsed[i]) continue;
for (int j=0;j<len;j++) { if (tUsed[j]) continue;
if (guess.charAt(i)==target.charAt(j)) { result[i]=1; tUsed[j]=true; break; } } }
return result;
}
static class LeaderboardEntry {
String name; int score; int stage;
LeaderboardEntry(String name, int score, int stage) {
this.name = name; this.score = score; this.stage = stage;
}
}
class HangmanPanel extends JPanel {
private int wrongGuesses = 0;
private int animatingPart = 0;
private float dropProgress = 1.0f;
private Timer dropTimer;
private int[] partDropOffsets = new int[7];
HangmanPanel() {
setOpaque(false);
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(GOLD_DIM, 1),
BorderFactory.createEmptyBorder(10,10,10,10)
));
}
void resetAnimation() {
wrongGuesses = 0;
animatingPart = 0;
dropProgress = 1.0f;
for (int i = 0; i < partDropOffsets.length; i++) partDropOffsets[i] = 0;
if (dropTimer != null) dropTimer.stop();
}
void triggerDropAnimation(int partNumber) {
if (partNumber < 1 || partNumber > 6) return;
wrongGuesses = partNumber;
animatingPart = partNumber;
dropProgress = 0.0f;
partDropOffsets[partNumber] = -80;