-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexiGuess.java
More file actions
2022 lines (1831 loc) · 109 KB
/
LexiGuess.java
File metadata and controls
2022 lines (1831 loc) · 109 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.awt.geom.*;
import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.List;
import javax.sound.sampled.*;
import javax.swing.*;
import javax.swing.Timer;
public class LexiGuess extends JFrame {
// ── Word Entry ────────────────────────────────────────────────────────────
static class WordEntry {
String word, clue, difficulty;
WordEntry(String word, String clue, String difficulty) {
this.word = word.toUpperCase().trim();
this.clue = clue;
this.difficulty = difficulty.toUpperCase().trim();
}
}
// ── JSON Loader ───────────────────────────────────────────────────────────
private static List<WordEntry> loadJson(String filePath) {
List<WordEntry> entries = new ArrayList<>();
try {
String raw = new String(Files.readAllBytes(Paths.get(filePath)));
String[] objects = raw.split("\\{");
for (String obj : objects) {
obj = obj.trim();
if (obj.isEmpty()) continue;
obj = obj.replaceAll("[}\\]]+\\s*$", "").trim();
String word = extractJsonValue(obj, "words");
if (word == null || word.isEmpty()) word = extractJsonValue(obj, "word");
String clue = extractJsonValue(obj, "clue");
String difficulty = extractJsonValue(obj, "difficulty");
if (word != null && !word.isEmpty() && clue != null && difficulty != null)
entries.add(new WordEntry(word, clue, difficulty));
}
} catch (IOException e) {
System.err.println("Could not load " + filePath + ": " + e.getMessage());
}
return entries;
}
private static String extractJsonValue(String obj, String key) {
java.util.regex.Matcher m =
java.util.regex.Pattern.compile("\"" + key + "\"\\s*:\\s*\"([^\"]+)\"").matcher(obj);
return m.find() ? m.group(1).trim() : null;
}
// ── Word Banks ────────────────────────────────────────────────────────────
private List<WordEntry> easyWords = new ArrayList<>();
private List<WordEntry> mediumWords = new ArrayList<>();
private List<WordEntry> hardWords = new ArrayList<>();
private void loadAllWords() {
easyWords = loadJson("easy.json");
mediumWords = loadJson("medium.json");
hardWords = loadJson("hard.json");
if (easyWords.isEmpty()) for (String[] e : new String[][]{
{"CODE","Instructions written for a computer to execute."},
{"LOOP","A structure that repeats a block of code."},
{"BYTE","A unit of data equal to 8 bits."},
{"TYPE","A classification specifying the kind of value a variable holds."},
{"VOID","A return type indicating a function returns nothing."}
}) easyWords.add(new WordEntry(e[0], e[1], "EASY"));
if (mediumWords.isEmpty()) for (String[] e : new String[][]{
{"ARRAY","A collection of elements stored at contiguous memory locations."},
{"STACK","A linear data structure following Last-In-First-Out order."},
{"QUEUE","A linear data structure following First-In-First-Out order."},
{"PARSE","To analyse a string of symbols according to formal grammar rules."},
{"CACHE","Temporary storage that speeds up future data requests."}
}) mediumWords.add(new WordEntry(e[0], e[1], "MEDIUM"));
if (hardWords.isEmpty()) for (String[] e : new String[][]{
{"MUTEX","A synchronisation primitive that prevents simultaneous resource access."},
{"PRAGMA","A compiler directive that provides additional information to the compiler."},
{"LAMBDA","An anonymous function defined without a name."},
{"DAEMON","A background process that runs without direct user interaction."},
{"ENDIAN","Describes the byte order used to represent multi-byte data."}
}) hardWords.add(new WordEntry(e[0], e[1], "HARD"));
}
// ══════════════════════════════════════════════════════════════════════════
// FUTURISTIC COLOUR PALETTE
// ══════════════════════════════════════════════════════════════════════════
private static final Color BG_VOID = new Color(4, 6, 14);
private static final Color BG_DEEP = new Color(8, 11, 22);
private static final Color BG_SURFACE = new Color(13, 17, 32);
private static final Color BG_ELEVATED = new Color(18, 23, 42);
private static final Color AMBER = new Color(255, 180, 30);
private static final Color AMBER_DIM = new Color(160, 105, 10);
private static final Color AMBER_GLOW = new Color(255, 140, 0, 70);
private static final Color AMBER_SUBTLE = new Color(255, 180, 30, 25);
private static final Color CYAN = new Color(50, 200, 255);
private static final Color CYAN_DIM = new Color(25, 110, 160);
private static final Color CYAN_GLOW = new Color(50, 200, 255, 60);
private static final Color TEXT_BRIGHT = new Color(230, 228, 218);
private static final Color TEXT_MID = new Color(150, 148, 165);
private static final Color TEXT_DIM = new Color(75, 73, 88);
private static final Color TILE_EMPTY_BG = new Color(16, 20, 38);
private static final Color TILE_EMPTY_BD = new Color(40, 44, 65);
private static final Color GREEN_CORRECT = new Color(40, 190, 110);
private static final Color YELLOW_PRESENT = new Color(210, 165, 30);
private static final Color GRAY_ABSENT = new Color(38, 38, 52);
private static final Color RED_DANGER = new Color(210, 60, 60);
private static final Color EASY_CLR = new Color(50, 205, 120);
private static final Color MEDIUM_CLR = new Color(210, 165, 30);
private static final Color HARD_CLR = new Color(215, 75, 75);
private static final Color CLUE_CLR = new Color(100, 180, 255);
// ── Sound ─────────────────────────────────────────────────────────────────
private static final String SOUND_CORRECT = "chrisiex1-correct-156911 (1).wav";
private static final String SOUND_LOSE = "freesound_community-080047_lose_funny_re.wav";
private static final String SOUND_KEYCLICK = "creatorshome-keyboard-click-327728.wav";
private static final String SOUND_START = "creatorshome-keyboard-click-327728.wav";
// ── Game State ────────────────────────────────────────────────────────────
private WordEntry currentEntry;
private String targetWord = "";
private String currentClue = "";
private String difficulty = "EASY";
private int maxAttempts = 6;
private int currentAttempt = 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 Set<String> usedWords = new HashSet<>();
private int currentLevel = 1;
private int totalLevels = 0;
private int wordLength;
private Map<String, Integer> difficultyProgress = new HashMap<>();
private List<LeaderboardEntry> leaderboard = new ArrayList<>();
private String currentPlayerName = "Player";
private final DatabaseManager db = new DatabaseManager();
// ── UI ────────────────────────────────────────────────────────────────────
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 clueLabel;
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;
private JPanel levelSelectPanel;
// ── Particle System ───────────────────────────────────────────────────────
static class Particle {
float x, y, vx, vy, life, maxLife, size;
Color color;
Particle(float x, float y, Color c) {
this.x = x; this.y = y;
float angle = (float)(Math.random() * Math.PI * 2);
float speed = (float)(Math.random() * 0.6 + 0.15);
vx = (float)Math.cos(angle) * speed;
vy = (float)Math.sin(angle) * speed - 0.5f;
life = maxLife = (float)(Math.random() * 220 + 80);
size = (float)(Math.random() * 2.2 + 0.6);
color = c;
}
void update() { x += vx; y += vy; vy += 0.012f; life--; }
boolean dead() { return life <= 0; }
float alpha() { return Math.max(0f, Math.min(1f, life / maxLife)); }
}
// ── Futuristic background panel ───────────────────────────────────────────
static class FuturisticBackground extends JPanel {
private final List<Particle> particles = new ArrayList<>();
private Timer animTimer;
private int frame = 0;
FuturisticBackground() {
setOpaque(true);
animTimer = new Timer(24, e -> { frame++; spawnParticles(); updateParticles(); repaint(); });
animTimer.start();
}
private void spawnParticles() {
if (frame % 4 == 0 && particles.size() < 80) {
int w = getWidth(); int h = getHeight();
if (w == 0) return;
float[] xs = {0, w, (float)(Math.random() * w)};
float[] ys = {h, h, h + 10};
int idx = (int)(Math.random() * xs.length);
Color c = Math.random() > 0.5 ? new Color(255, 180, 30) : new Color(50, 200, 255);
particles.add(new Particle(xs[idx], ys[idx], c));
}
}
private void updateParticles() {
particles.removeIf(Particle::dead);
particles.forEach(Particle::update);
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
int w = getWidth(), h = getHeight();
GradientPaint bg = new GradientPaint(0, 0, new Color(6, 8, 18), 0, h, new Color(4, 5, 12));
g2.setPaint(bg); g2.fillRect(0, 0, w, h);
RadialGradientPaint glowBL = new RadialGradientPaint(
new Point2D.Float(0, h), Math.max(w, h) * 0.65f,
new float[]{0f, 0.4f, 1f},
new Color[]{new Color(200, 100, 0, 60), new Color(160, 60, 0, 18), new Color(0, 0, 0, 0)});
g2.setPaint(glowBL); g2.fillRect(0, 0, w, h);
RadialGradientPaint glowTR = new RadialGradientPaint(
new Point2D.Float(w, 0), Math.max(w, h) * 0.55f,
new float[]{0f, 0.35f, 1f},
new Color[]{new Color(0, 100, 180, 45), new Color(0, 60, 120, 12), new Color(0, 0, 0, 0)});
g2.setPaint(glowTR); g2.fillRect(0, 0, w, h);
drawHexGrid(g2, w, h);
drawCircuitLines(g2, w, h);
for (Particle p : particles) {
float a = p.alpha();
int alphaMain = Math.max(0, Math.min(255, (int)(a * 200)));
int alphaHalo = Math.max(0, Math.min(255, (int)(a * 40)));
Color halo = new Color(p.color.getRed(), p.color.getGreen(), p.color.getBlue(), alphaHalo);
g2.setColor(halo);
g2.fill(new Ellipse2D.Float(p.x - p.size * 3, p.y - p.size * 3, p.size * 6, p.size * 6));
Color pc = new Color(p.color.getRed(), p.color.getGreen(), p.color.getBlue(), alphaMain);
g2.setColor(pc);
g2.fill(new Ellipse2D.Float(p.x - p.size / 2, p.y - p.size / 2, p.size, p.size));
}
g2.setColor(new Color(0, 0, 0, 12));
for (int y = 0; y < h; y += 3) g2.drawLine(0, y, w, y);
g2.dispose();
super.paintChildren(g);
}
private void drawHexGrid(Graphics2D g2, int w, int h) {
int hexR = 38;
int hexW = (int)(hexR * Math.sqrt(3));
int hexH = hexR * 2;
g2.setStroke(new BasicStroke(0.6f));
for (int row = -1; row < h / (hexH * 3 / 4) + 2; row++) {
for (int col = -1; col < w / hexW + 2; col++) {
int cx = col * hexW + (row % 2 == 1 ? hexW / 2 : 0);
int cy = row * (hexH * 3 / 4);
double distToCorner = Math.min(
Math.sqrt(cx * cx + (h - cy) * (h - cy)),
Math.sqrt((w - cx) * (w - cx) + cy * cy)) / Math.sqrt(w * w + h * h);
int alpha = (int)(8 + distToCorner * 10);
g2.setColor(new Color(80, 140, 200, Math.min(22, alpha)));
drawHex(g2, cx, cy, hexR);
}
}
}
private void drawHex(Graphics2D g2, int cx, int cy, int r) {
int[] xs = new int[6], ys = new int[6];
for (int i = 0; i < 6; i++) {
double angle = Math.PI / 180.0 * (60 * i - 30);
xs[i] = cx + (int)(r * Math.cos(angle));
ys[i] = cy + (int)(r * Math.sin(angle));
}
g2.drawPolygon(xs, ys, 6);
}
private void drawCircuitLines(Graphics2D g2, int w, int h) {
g2.setStroke(new BasicStroke(0.8f));
Random rng = new Random(42);
for (int i = 0; i < 12; i++) {
int x1 = rng.nextInt(w), y1 = rng.nextInt(h);
int x2 = x1 + (rng.nextBoolean() ? rng.nextInt(120) : 0);
int y2 = y1 + (rng.nextBoolean() ? rng.nextInt(80) : 0);
boolean isAmber = rng.nextBoolean();
Color lc = isAmber ? new Color(255, 160, 20, 18) : new Color(30, 160, 220, 14);
g2.setColor(lc);
g2.drawLine(x1, y1, x2, y1);
g2.drawLine(x2, y1, x2, y2);
g2.setColor(new Color(lc.getRed(), lc.getGreen(), lc.getBlue(), 55));
g2.fillOval(x2 - 3, y2 - 3, 6, 6);
}
}
void stopAnimation() { if (animTimer != null) animTimer.stop(); }
}
// ── Transparent panel helper ──────────────────────────────────────────────
private JPanel makeTransparentPanel() {
JPanel p = new JPanel(); p.setOpaque(false); return p;
}
// ── Glow border button ────────────────────────────────────────────────────
private JButton makeGlowButton(String text, Color accent) {
JButton btn = new JButton(text) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 22));
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
super.paintComponent(g2);
g2.dispose();
}
};
btn.setFont(new Font("Monospaced", Font.BOLD, 13));
btn.setForeground(accent);
btn.setContentAreaFilled(false); btn.setBorderPainted(false);
btn.setFocusPainted(false); btn.setOpaque(false);
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btn.setBorder(BorderFactory.createCompoundBorder(
new GlowBorder(accent, 1, 8),
BorderFactory.createEmptyBorder(7, 18, 7, 18)));
btn.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
btn.setForeground(accent.brighter());
btn.setBorder(BorderFactory.createCompoundBorder(
new GlowBorder(accent.brighter(), 2, 8),
BorderFactory.createEmptyBorder(6, 17, 6, 17)));
btn.repaint();
}
public void mouseExited(MouseEvent e) {
btn.setForeground(accent);
btn.setBorder(BorderFactory.createCompoundBorder(
new GlowBorder(accent, 1, 8),
BorderFactory.createEmptyBorder(7, 18, 7, 18)));
btn.repaint();
}
});
return btn;
}
// ── Primary CTA button ────────────────────────────────────────────────────
private JButton makePrimaryButton(String text) {
JButton btn = new JButton(text) {
private boolean hover = false;
{ addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) { hover = true; repaint(); }
public void mouseExited (MouseEvent e) { hover = false; repaint(); }
}); }
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color a = AMBER, b = new Color(200, 120, 0);
if (hover) { a = a.brighter(); b = b.brighter(); }
GradientPaint gp = new GradientPaint(0, 0, a, 0, getHeight(), b);
g2.setPaint(gp);
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
g2.setColor(new Color(255, 180, 30, 60));
g2.setStroke(new BasicStroke(3f));
g2.drawRoundRect(1, 1, getWidth()-2, getHeight()-2, 10, 10);
g2.dispose();
super.paintComponent(g);
}
};
btn.setFont(new Font("Monospaced", Font.BOLD, 18));
btn.setForeground(new Color(10, 8, 2));
btn.setContentAreaFilled(false); btn.setBorderPainted(false);
btn.setFocusPainted(false); btn.setOpaque(false);
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btn.setPreferredSize(new Dimension(260, 58));
btn.setMaximumSize(new Dimension(260, 58));
btn.setAlignmentX(CENTER_ALIGNMENT);
return btn;
}
// ── Custom glow border ────────────────────────────────────────────────────
static class GlowBorder extends javax.swing.border.AbstractBorder {
private final Color color; private final int thick, radius;
GlowBorder(Color c, int t, int r) { color = c; thick = t; radius = r; }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 35));
g2.setStroke(new BasicStroke(thick + 4));
g2.drawRoundRect(x+2, y+2, w-4, h-4, radius+2, radius+2);
g2.setColor(color);
g2.setStroke(new BasicStroke(thick));
g2.drawRoundRect(x+1, y+1, w-2, h-2, radius, radius);
g2.dispose();
}
@Override public Insets getBorderInsets(Component c) { return new Insets(thick+2, thick+2, thick+2, thick+2); }
}
// ── Section title ─────────────────────────────────────────────────────────
private JLabel makeSectionTitle(String text) {
JLabel lbl = new JLabel(text, SwingConstants.CENTER) {
@Override protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
int mid = getWidth() / 2;
int y = getHeight() - 5;
GradientPaint fade = new GradientPaint(mid - 60, y, new Color(255, 180, 30, 0), mid, y, AMBER, false);
GradientPaint fade2 = new GradientPaint(mid, y, AMBER, mid + 60, y, new Color(255, 180, 30, 0), false);
g2.setStroke(new BasicStroke(1.5f));
g2.setPaint(fade); g2.drawLine(mid - 60, y, mid, y);
g2.setPaint(fade2); g2.drawLine(mid, y, mid + 60, y);
g2.dispose();
}
};
lbl.setFont(new Font("Monospaced", Font.BOLD, 14));
lbl.setForeground(AMBER_DIM);
lbl.setAlignmentX(CENTER_ALIGNMENT);
lbl.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
return lbl;
}
private JLabel makeHexOrnament(String text) {
JLabel lbl = new JLabel(text, SwingConstants.CENTER);
lbl.setFont(new Font("Monospaced", Font.PLAIN, 11));
lbl.setForeground(new Color(80, 70, 35));
lbl.setAlignmentX(CENTER_ALIGNMENT);
return lbl;
}
// ── Sound ─────────────────────────────────────────────────────────────────
private void playSound(String filePath) {
new Thread(() -> {
try {
File f = new File(filePath); if (!f.exists()) return;
AudioInputStream ai = AudioSystem.getAudioInputStream(f);
Clip clip = AudioSystem.getClip(); clip.open(ai); clip.start();
clip.addLineListener(ev -> { if (ev.getType() == LineEvent.Type.STOP) clip.close(); });
} catch (Exception ignored) {}
}).start();
}
// ── Constructor ───────────────────────────────────────────────────────────
public LexiGuess() {
loadAllWords(); db.connect();
Runtime.getRuntime().addShutdownHook(new Thread(db::disconnect));
difficultyProgress.put("EASY", 1); difficultyProgress.put("MEDIUM", 1); difficultyProgress.put("HARD", 1);
setTitle("LexiGuess — Programming Enhancement Game");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
getContentPane().setBackground(BG_VOID);
cardLayout = new CardLayout(); cardPanel = new JPanel(cardLayout);
cardPanel.setBackground(BG_VOID);
cardPanel.add(buildStartScreen(), "START");
cardPanel.add(buildMenuScreen(), "MENU");
cardPanel.add(buildLevelSelectScreen(), "LEVELSELECT");
cardPanel.add(buildGameScreen(), "GAME");
cardPanel.add(buildInstructionsScreen(), "INSTRUCTIONS");
cardPanel.add(buildLeaderboardScreen(), "LEADERBOARD");
add(cardPanel);
setSize(980, 840);
setLocationRelativeTo(null);
setVisible(true);
cardLayout.show(cardPanel, "START");
}
// ── End Game Dialog ───────────────────────────────────────────────────────
private void showEndGameDialog(String title, String message, String word,
String subMessage, Color accentColor, String retryLabel) {
JDialog dialog = new JDialog(this, title, true);
dialog.setUndecorated(true);
dialog.setSize(480, 400);
dialog.setLocationRelativeTo(this);
JPanel panel = new JPanel() {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(BG_SURFACE);
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 20, 20);
GradientPaint topBar = new GradientPaint(0, 0,
new Color(accentColor.getRed(), accentColor.getGreen(), accentColor.getBlue(), 180),
getWidth(), 0, new Color(accentColor.getRed(), accentColor.getGreen(), accentColor.getBlue(), 0));
g2.setPaint(topBar); g2.fillRoundRect(0, 0, getWidth(), 4, 20, 20);
g2.setColor(new Color(accentColor.getRed(), accentColor.getGreen(), accentColor.getBlue(), 80));
g2.setStroke(new BasicStroke(2f));
g2.drawRoundRect(1, 1, getWidth()-3, getHeight()-3, 20, 20);
RadialGradientPaint innerGlow = new RadialGradientPaint(
new Point2D.Float(getWidth()/2f, 0), getWidth()/2f,
new float[]{0f, 1f},
new Color[]{new Color(accentColor.getRed(), accentColor.getGreen(), accentColor.getBlue(), 25), new Color(0,0,0,0)});
g2.setPaint(innerGlow); g2.fillRect(0, 0, getWidth(), 80);
g2.dispose();
}
};
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(30, 45, 28, 45));
panel.setOpaque(false);
JLabel hex = makeHexOrnament("[ ◈ SYSTEM REPORT ◈ ]");
hex.setForeground(new Color(accentColor.getRed(), accentColor.getGreen(), accentColor.getBlue(), 130));
panel.add(hex); panel.add(Box.createVerticalStrut(10));
JLabel titleLabel = new JLabel(title, SwingConstants.CENTER);
titleLabel.setFont(new Font("Monospaced", Font.BOLD, 26));
titleLabel.setForeground(accentColor.equals(RED_DANGER) ? RED_DANGER : AMBER);
titleLabel.setAlignmentX(CENTER_ALIGNMENT);
panel.add(titleLabel); panel.add(Box.createVerticalStrut(10));
JLabel msgLabel = new JLabel(message, SwingConstants.CENTER);
msgLabel.setFont(new Font("Monospaced", Font.PLAIN, 12)); msgLabel.setForeground(TEXT_MID);
msgLabel.setAlignmentX(CENTER_ALIGNMENT);
panel.add(msgLabel); panel.add(Box.createVerticalStrut(8));
JLabel wordLabel = new JLabel(word, SwingConstants.CENTER) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(accentColor.getRed(), accentColor.getGreen(), accentColor.getBlue(), 30));
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
g2.setColor(new Color(accentColor.getRed(), accentColor.getGreen(), accentColor.getBlue(), 90));
g2.setStroke(new BasicStroke(1f));
g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 8, 8);
g2.dispose();
super.paintComponent(g);
}
};
wordLabel.setFont(new Font("Monospaced", Font.BOLD, 36));
wordLabel.setForeground(TEXT_BRIGHT);
wordLabel.setAlignmentX(CENTER_ALIGNMENT);
wordLabel.setBorder(BorderFactory.createEmptyBorder(6, 20, 6, 20));
wordLabel.setOpaque(false);
panel.add(wordLabel); panel.add(Box.createVerticalStrut(10));
JLabel clueDialogLabel = new JLabel(
"<html><div style='text-align:center;width:340px;font-family:monospace'>" + currentClue + "</div></html>",
SwingConstants.CENTER);
clueDialogLabel.setFont(new Font("Monospaced", Font.ITALIC, 12));
clueDialogLabel.setForeground(CLUE_CLR); clueDialogLabel.setAlignmentX(CENTER_ALIGNMENT);
panel.add(clueDialogLabel); panel.add(Box.createVerticalStrut(6));
JLabel subLabel = new JLabel(subMessage, SwingConstants.CENTER);
subLabel.setFont(new Font("Monospaced", Font.BOLD, 13));
subLabel.setForeground(accentColor.equals(RED_DANGER) ? RED_DANGER : AMBER);
subLabel.setAlignmentX(CENTER_ALIGNMENT);
panel.add(subLabel); panel.add(Box.createVerticalStrut(26));
JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 14, 0));
btnPanel.setOpaque(false);
JButton retryBtn = makeGlowButton(retryLabel, accentColor.equals(RED_DANGER) ? RED_DANGER : GREEN_CORRECT);
retryBtn.addActionListener(e -> { dialog.dispose(); startGame(); });
JButton lvlBtn = makeGlowButton("Level Select", AMBER);
lvlBtn.addActionListener(e -> { dialog.dispose(); updateLevelSelectScreen(); cardLayout.show(cardPanel, "LEVELSELECT"); });
JButton exitBtn = makeGlowButton("Exit", TEXT_MID);
exitBtn.addActionListener(e -> System.exit(0));
btnPanel.add(retryBtn); btnPanel.add(lvlBtn); btnPanel.add(exitBtn);
btnPanel.setAlignmentX(CENTER_ALIGNMENT);
panel.add(btnPanel);
dialog.setContentPane(panel);
dialog.getContentPane().setBackground(BG_SURFACE);
dialog.setVisible(true);
}
// ── Start Screen ──────────────────────────────────────────────────────────
private JPanel buildStartScreen() {
FuturisticBackground root = new FuturisticBackground();
root.setLayout(new BorderLayout());
JPanel center = makeTransparentPanel();
center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
center.setBorder(BorderFactory.createEmptyBorder(80, 100, 80, 100));
JLabel hexTag = makeHexOrnament("◈ v2.0 · programming_challenge.exe ◈");
hexTag.setFont(new Font("Monospaced", Font.PLAIN, 12));
hexTag.setForeground(CYAN_DIM);
center.add(hexTag);
center.add(Box.createVerticalStrut(18));
JLabel title = new JLabel("LexiGuess", SwingConstants.CENTER) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setFont(getFont()); g2.setColor(new Color(255, 160, 0, 55));
g2.drawString(getText(), 3, getHeight() - 18);
g2.dispose();
super.paintComponent(g);
}
};
title.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 82));
title.setForeground(AMBER);
title.setAlignmentX(CENTER_ALIGNMENT);
center.add(title);
JLabel sub = new JLabel("Programming Enhancement Game", SwingConstants.CENTER);
sub.setFont(new Font("Monospaced", Font.PLAIN, 15));
sub.setForeground(TEXT_MID); sub.setAlignmentX(CENTER_ALIGNMENT);
center.add(sub);
center.add(Box.createVerticalStrut(6));
JPanel sep = makeSeparatorLine(AMBER, 180);
sep.setAlignmentX(CENTER_ALIGNMENT);
center.add(sep);
center.add(Box.createVerticalStrut(38));
JLabel nameLbl = makeHexOrnament("// player_name");
nameLbl.setFont(new Font("Monospaced", Font.PLAIN, 13)); nameLbl.setForeground(CYAN_DIM);
center.add(nameLbl); center.add(Box.createVerticalStrut(8));
JTextField nameField = new JTextField("Player", 15) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(14, 20, 40)); g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
g2.setColor(new Color(50, 200, 255, 80)); g2.setStroke(new BasicStroke(1f));
g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 8, 8);
g2.dispose();
super.paintComponent(g);
}
};
nameField.setFont(new Font("Monospaced", Font.BOLD, 18));
nameField.setForeground(TEXT_BRIGHT); nameField.setOpaque(false);
nameField.setBackground(new Color(0,0,0,0)); nameField.setCaretColor(AMBER);
nameField.setHorizontalAlignment(SwingConstants.CENTER);
nameField.setBorder(BorderFactory.createEmptyBorder(10, 16, 10, 16));
nameField.setMaximumSize(new Dimension(280, 50)); nameField.setAlignmentX(CENTER_ALIGNMENT);
center.add(nameField);
center.add(Box.createVerticalStrut(36));
JButton startBtn = makePrimaryButton("▶ START GAME");
startBtn.addActionListener(e -> {
String name = nameField.getText().trim();
if (!name.isEmpty()) currentPlayerName = name;
if (db.isConnected()) {
java.util.Map<String, Integer> saved = db.loadAllProgress(currentPlayerName);
difficultyProgress.put("EASY", saved.get("EASY"));
difficultyProgress.put("MEDIUM", saved.get("MEDIUM"));
difficultyProgress.put("HARD", saved.get("HARD"));
}
playSound(SOUND_START); cardLayout.show(cardPanel, "MENU");
});
center.add(startBtn); center.add(Box.createVerticalStrut(14));
JPanel rowBtns = new JPanel(new FlowLayout(FlowLayout.CENTER, 12, 0));
rowBtns.setOpaque(false); rowBtns.setAlignmentX(CENTER_ALIGNMENT);
JButton leaderBtn = makeGlowButton("★ Leaderboard", AMBER_DIM);
leaderBtn.addActionListener(e -> { updateLeaderboardDisplay(); cardLayout.show(cardPanel, "LEADERBOARD"); });
JButton exitBtn = makeGlowButton("✕ Exit", new Color(140, 50, 50));
exitBtn.addActionListener(e -> System.exit(0));
rowBtns.add(leaderBtn); rowBtns.add(exitBtn);
center.add(rowBtns);
center.add(Box.createVerticalStrut(28));
JLabel hint = makeHexOrnament("//. Awaiting input... ready to compile your first guess");
hint.setForeground(new Color(40, 60, 30));
center.add(hint);
root.add(center, BorderLayout.CENTER);
return root;
}
private JPanel makeSeparatorLine(Color c, int width) {
return new JPanel() {
{ setOpaque(false); setPreferredSize(new Dimension(width, 2));
setMaximumSize(new Dimension(width, 2)); }
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
GradientPaint gp = new GradientPaint(0, 0, new Color(c.getRed(), c.getGreen(), c.getBlue(), 0), getWidth()/2, 0, c, false);
GradientPaint gp2 = new GradientPaint(getWidth()/2, 0, c, getWidth(), 0, new Color(c.getRed(), c.getGreen(), c.getBlue(), 0), false);
g2.setPaint(gp); g2.fillRect(0, 0, getWidth()/2, getHeight());
g2.setPaint(gp2); g2.fillRect(getWidth()/2, 0, getWidth()/2, getHeight());
g2.dispose();
}
};
}
// ── Menu Screen ───────────────────────────────────────────────────────────
private JPanel buildMenuScreen() {
FuturisticBackground root = new FuturisticBackground();
root.setLayout(new BorderLayout());
JPanel topBar = new JPanel(new BorderLayout()) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(new Color(8, 11, 22, 200)); g2.fillRect(0, 0, getWidth(), getHeight());
g2.setColor(new Color(255, 180, 30, 50)); g2.setStroke(new BasicStroke(1f));
g2.drawLine(0, getHeight()-1, getWidth(), getHeight()-1);
g2.dispose();
}
};
topBar.setOpaque(false);
topBar.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
JLabel logoSmall = new JLabel("⬡ LexiGuess", SwingConstants.LEFT);
logoSmall.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 22)); logoSmall.setForeground(AMBER);
topBar.add(logoSmall, BorderLayout.WEST);
JPanel navRight = new JPanel(new FlowLayout(FlowLayout.RIGHT, 16, 0));
navRight.setOpaque(false);
JButton instrBtn = makeGlowButton("[ How to Play ]", AMBER_DIM);
instrBtn.addActionListener(e -> cardLayout.show(cardPanel, "INSTRUCTIONS"));
JButton leaderBtn = makeGlowButton("[ Leaderboard ]", CYAN_DIM);
leaderBtn.addActionListener(e -> { updateLeaderboardDisplay(); cardLayout.show(cardPanel, "LEADERBOARD"); });
JButton exitBtn = makeGlowButton("[ Exit ]", new Color(120, 45, 45));
exitBtn.addActionListener(e -> System.exit(0));
navRight.add(instrBtn); navRight.add(leaderBtn); navRight.add(exitBtn);
topBar.add(navRight, BorderLayout.EAST);
root.add(topBar, BorderLayout.NORTH);
JPanel center = makeTransparentPanel();
center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
center.setBorder(BorderFactory.createEmptyBorder(22, 60, 20, 60));
center.add(makeSectionTitle("◈ SELECT YOUR CHALLENGE ◈"));
center.add(Box.createVerticalStrut(22));
JPanel diffRow = new JPanel(new FlowLayout(FlowLayout.CENTER, 22, 0));
diffRow.setOpaque(false);
diffRow.add(makeDiffCard("EASY", "Novice", "Common concepts", EASY_CLR, easyWords.size()));
diffRow.add(makeDiffCard("MEDIUM", "Scholar", "Intermediate terms", MEDIUM_CLR, mediumWords.size()));
diffRow.add(makeDiffCard("HARD", "Mastermind", "Advanced jargon", HARD_CLR, hardWords.size()));
center.add(diffRow);
center.add(Box.createVerticalStrut(28));
sessionScoreLabel = new JLabel("[ Session Score: 0 · Stage: 1 ]", SwingConstants.CENTER);
sessionScoreLabel.setFont(new Font("Monospaced", Font.BOLD, 15));
sessionScoreLabel.setForeground(AMBER); sessionScoreLabel.setAlignmentX(CENTER_ALIGNMENT);
center.add(sessionScoreLabel);
root.add(center, BorderLayout.CENTER);
JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.CENTER)) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(new Color(6, 9, 18, 180)); g2.fillRect(0, 0, getWidth(), getHeight());
g2.setColor(new Color(255, 180, 30, 35)); g2.drawLine(0, 0, getWidth(), 0);
g2.dispose();
}
};
statusBar.setOpaque(false);
JLabel statusLbl = new JLabel("◈ SYSTEM ONLINE · DATABASE CONNECTED · AWAITING SELECTION ◈");
statusLbl.setFont(new Font("Monospaced", Font.PLAIN, 10)); statusLbl.setForeground(new Color(50, 50, 35));
statusBar.add(statusLbl);
root.add(statusBar, BorderLayout.SOUTH);
return root;
}
// ── Difficulty Card ───────────────────────────────────────────────────────
private JPanel makeDiffCard(String diff, String rankTitle, String descriptor,
Color accent, int wordCount) {
JPanel card = new JPanel() {
private boolean hover = false;
{ setOpaque(false);
addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) { hover = true; repaint(); }
public void mouseExited (MouseEvent e) { hover = false; repaint(); }
}); }
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(accent.getRed()/5, accent.getGreen()/5, accent.getBlue()/5, 255));
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 16, 16);
g2.setColor(new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 8));
for (int y = 0; y < getHeight(); y += 22)
for (int x = 0; x < getWidth(); x += 28)
drawMiniHex(g2, x + (y/22 % 2 == 0 ? 0 : 14), y);
if (hover) {
g2.setColor(new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 100));
g2.setStroke(new BasicStroke(3f));
g2.drawRoundRect(1, 1, getWidth()-3, getHeight()-3, 15, 15);
GradientPaint topGlow = new GradientPaint(0, 0,
new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 160),
getWidth(), 0, new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 0));
g2.setPaint(topGlow); g2.fillRoundRect(0, 0, getWidth(), 3, 15, 15);
} else {
g2.setColor(new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 60));
g2.setStroke(new BasicStroke(1.5f));
g2.drawRoundRect(1, 1, getWidth()-3, getHeight()-3, 15, 15);
}
g2.dispose();
super.paintComponent(g);
}
private void drawMiniHex(Graphics2D g2, int cx, int cy) {
int r = 9; int[] xs = new int[6], ys = new int[6];
for (int i = 0; i < 6; i++) {
double ang = Math.PI / 180.0 * (60*i - 30);
xs[i] = cx + (int)(r * Math.cos(ang)); ys[i] = cy + (int)(r * Math.sin(ang));
}
g2.drawPolygon(xs, ys, 6);
}
};
card.setLayout(new BoxLayout(card, BoxLayout.Y_AXIS));
card.setPreferredSize(new Dimension(218, 255));
card.setBorder(BorderFactory.createEmptyBorder(20, 18, 20, 18));
card.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
JPanel accentLine = new JPanel() {
{ setOpaque(false); setMaximumSize(new Dimension(180, 2)); }
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
GradientPaint gp = new GradientPaint(0, 0, new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 0), getWidth()/2, 0, accent, false);
GradientPaint gp2 = new GradientPaint(getWidth()/2, 0, accent, getWidth(), 0, new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 0), false);
g2.setPaint(gp); g2.fillRect(0, 0, getWidth()/2, getHeight());
g2.setPaint(gp2); g2.fillRect(getWidth()/2, 0, getWidth()/2, getHeight());
g2.dispose();
}
};
accentLine.setAlignmentX(CENTER_ALIGNMENT);
JLabel diffLbl = new JLabel(diff, SwingConstants.CENTER);
diffLbl.setFont(new Font("Monospaced", Font.BOLD, 22)); diffLbl.setForeground(accent);
diffLbl.setAlignmentX(CENTER_ALIGNMENT);
JLabel rankLbl = new JLabel("[ " + rankTitle + " ]", SwingConstants.CENTER);
rankLbl.setFont(new Font("Monospaced", Font.PLAIN, 11));
rankLbl.setForeground(new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 160));
rankLbl.setAlignmentX(CENTER_ALIGNMENT);
JLabel descLbl = new JLabel(descriptor, SwingConstants.CENTER);
descLbl.setFont(new Font("Monospaced", Font.PLAIN, 11)); descLbl.setForeground(TEXT_MID);
descLbl.setAlignmentX(CENTER_ALIGNMENT);
JLabel countLbl = new JLabel("6 attempts · " + wordCount + " levels", SwingConstants.CENTER);
countLbl.setFont(new Font("Monospaced", Font.PLAIN, 10)); countLbl.setForeground(TEXT_DIM);
countLbl.setAlignmentX(CENTER_ALIGNMENT);
JLabel clueLbl = new JLabel("✦ Clue included", SwingConstants.CENTER);
clueLbl.setFont(new Font("Monospaced", Font.PLAIN, 10)); clueLbl.setForeground(CYAN_DIM);
clueLbl.setAlignmentX(CENTER_ALIGNMENT);
JButton playBtn = makeGlowButton("SELECT LEVEL →", accent);
playBtn.setFont(new Font("Monospaced", Font.BOLD, 11));
playBtn.setMaximumSize(new Dimension(170, 34)); playBtn.setAlignmentX(CENTER_ALIGNMENT);
playBtn.addActionListener(e -> {
difficulty = diff;
currentLevel = difficultyProgress.getOrDefault(diff, 1);
updateLevelSelectScreen();
cardLayout.show(cardPanel, "LEVELSELECT");
});
card.add(accentLine); card.add(Box.createVerticalStrut(10));
card.add(diffLbl); card.add(rankLbl); card.add(Box.createVerticalStrut(10));
card.add(descLbl); card.add(countLbl); card.add(Box.createVerticalStrut(4));
card.add(clueLbl); card.add(Box.createVerticalGlue()); card.add(playBtn);
return card;
}
// ── Level Select Screen ───────────────────────────────────────────────────
private JPanel buildLevelSelectScreen() {
FuturisticBackground root = new FuturisticBackground();
root.setLayout(new BorderLayout());
JPanel topBar = new JPanel(new BorderLayout()) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(new Color(6, 9, 20, 220)); g2.fillRect(0, 0, getWidth(), getHeight());
g2.setColor(new Color(255, 180, 30, 45)); g2.drawLine(0, getHeight()-1, getWidth(), getHeight()-1);
g2.dispose();
}
};
topBar.setOpaque(false);
topBar.setBorder(BorderFactory.createEmptyBorder(12, 20, 12, 20));
JButton backBtn = makeGlowButton("← Back", AMBER_DIM);
backBtn.addActionListener(e -> cardLayout.show(cardPanel, "MENU"));
topBar.add(backBtn, BorderLayout.WEST);
JLabel titleLbl = new JLabel("◈ SKILL TREE ◈", SwingConstants.CENTER);
titleLbl.setFont(new Font("Monospaced", Font.BOLD, 22)); titleLbl.setForeground(AMBER);
topBar.add(titleLbl, BorderLayout.CENTER);
root.add(topBar, BorderLayout.NORTH);
levelSelectPanel = new JPanel();
levelSelectPanel.setOpaque(false);
levelSelectPanel.setBorder(BorderFactory.createEmptyBorder(28, 50, 28, 50));
JScrollPane scroll = new JScrollPane(levelSelectPanel);
scroll.setOpaque(false); scroll.getViewport().setOpaque(false); scroll.setBorder(null);
scroll.getVerticalScrollBar().setUnitIncrement(16);
scroll.getVerticalScrollBar().setBackground(BG_DEEP);
root.add(scroll, BorderLayout.CENTER);
JPanel botBar = new JPanel(new FlowLayout(FlowLayout.CENTER)) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(new Color(6, 9, 20, 180)); g2.fillRect(0, 0, getWidth(), getHeight());
g2.dispose();
}
};
botBar.setOpaque(false);
JLabel botLbl = new JLabel("◈ Defeat each level to unlock the next node ◈");
botLbl.setFont(new Font("Monospaced", Font.PLAIN, 10)); botLbl.setForeground(new Color(50, 50, 35));
botBar.add(botLbl); root.add(botBar, BorderLayout.SOUTH);
return root;
}
private void updateLevelSelectScreen() {
levelSelectPanel.removeAll();
levelSelectPanel.setLayout(new BoxLayout(levelSelectPanel, BoxLayout.Y_AXIS));
List<WordEntry> bank = difficulty.equals("EASY") ? easyWords
: difficulty.equals("MEDIUM") ? mediumWords : hardWords;
totalLevels = bank.size();
Color accent = difficulty.equals("EASY") ? EASY_CLR : difficulty.equals("MEDIUM") ? MEDIUM_CLR : HARD_CLR;
int highestUnlocked = difficultyProgress.getOrDefault(difficulty, 1);
JLabel diffLbl = new JLabel(difficulty + " — Skill Tree", SwingConstants.CENTER);
diffLbl.setFont(new Font("Monospaced", Font.BOLD, 20)); diffLbl.setForeground(accent);
diffLbl.setAlignmentX(CENTER_ALIGNMENT); levelSelectPanel.add(diffLbl);
int cleared = highestUnlocked - 1;
JLabel progressLbl = new JLabel(cleared + " of " + totalLevels + " nodes cleared", SwingConstants.CENTER);
progressLbl.setFont(new Font("Monospaced", Font.PLAIN, 12)); progressLbl.setForeground(TEXT_MID);
progressLbl.setAlignmentX(CENTER_ALIGNMENT);
levelSelectPanel.add(Box.createVerticalStrut(6)); levelSelectPanel.add(progressLbl);
JPanel progressBarWrapper = new JPanel() {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(20, 24, 40)); g2.fillRoundRect(0, 4, getWidth(), 6, 6, 6);
if (totalLevels > 0) {
int filled = (int)((double)cleared / totalLevels * getWidth());
GradientPaint gp = new GradientPaint(0, 0, accent.darker(), filled, 0, accent);
g2.setPaint(gp); g2.fillRoundRect(0, 4, filled, 6, 6, 6);
}
g2.dispose();
}
};
progressBarWrapper.setOpaque(false);
progressBarWrapper.setPreferredSize(new Dimension(600, 14));
progressBarWrapper.setMaximumSize(new Dimension(600, 14));
progressBarWrapper.setAlignmentX(CENTER_ALIGNMENT);
levelSelectPanel.add(Box.createVerticalStrut(8)); levelSelectPanel.add(progressBarWrapper);
levelSelectPanel.add(Box.createVerticalStrut(24));
int cols = 5;
int rows = (int) Math.ceil((double) totalLevels / cols);
JPanel grid = new JPanel(new GridLayout(rows, cols, 18, 18));
grid.setOpaque(false);
grid.setMaximumSize(new Dimension(680, rows * 115));
grid.setAlignmentX(CENTER_ALIGNMENT);
for (int i = 1; i <= totalLevels; i++) {
final int lvl = i;
boolean isCleared = (i < highestUnlocked);
boolean isUnlocked = (i <= highestUnlocked);
boolean isCurrent = (i == highestUnlocked);
JPanel cell = new JPanel() {
private boolean hover = false;
{ if (isUnlocked) addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) { hover = true; repaint(); }
public void mouseExited (MouseEvent e) { hover = false; repaint(); }
}); }
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color bg;
if (isCleared) bg = new Color(accent.getRed()/7, accent.getGreen()/7, accent.getBlue()/7, 255);
else if (isUnlocked) bg = new Color(18, 22, 42);
else bg = new Color(10, 12, 24);
g2.setColor(bg); g2.fillRoundRect(0, 0, getWidth(), getHeight(), 14, 14);
float thick = (hover || isCurrent) ? 2.5f : 1.2f;
Color bd = isCleared ? accent
: isCurrent ? new Color(accent.getRed(), accent.getGreen(), accent.getBlue(), 200)
: isUnlocked ? new Color(AMBER_DIM.getRed(), AMBER_DIM.getGreen(), AMBER_DIM.getBlue(), hover ? 180 : 80)
: new Color(28, 30, 45);
g2.setColor(bd); g2.setStroke(new BasicStroke(thick));
g2.drawRoundRect(1, 1, getWidth()-3, getHeight()-3, 13, 13);
g2.dispose();
super.paintComponent(g);
}
};
cell.setLayout(new BoxLayout(cell, BoxLayout.Y_AXIS));
cell.setOpaque(false);
cell.setPreferredSize(new Dimension(114, 98));
cell.setBorder(BorderFactory.createEmptyBorder(10, 8, 10, 8));
if (isUnlocked) cell.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
String numText = isUnlocked ? String.valueOf(lvl) : "⬡";
JLabel numLbl = new JLabel(numText, SwingConstants.CENTER);
numLbl.setFont(new Font("Monospaced", Font.BOLD, isUnlocked ? 28 : 18));
numLbl.setForeground(isCleared ? accent : isUnlocked ? TEXT_BRIGHT : new Color(35, 35, 50));
numLbl.setAlignmentX(CENTER_ALIGNMENT);
String statusText = isCleared ? "✦ Cleared" : isCurrent ? "▶ Play" : isUnlocked ? "Unlocked" : "Locked";
JLabel statusLbl = new JLabel(statusText, SwingConstants.CENTER);
statusLbl.setFont(new Font("Monospaced", Font.PLAIN, 10));
statusLbl.setForeground(isCleared ? accent : isCurrent ? AMBER : isUnlocked ? TEXT_MID : new Color(35,35,50));
statusLbl.setAlignmentX(CENTER_ALIGNMENT);
cell.add(Box.createVerticalGlue());
cell.add(numLbl); cell.add(Box.createVerticalStrut(5)); cell.add(statusLbl);
cell.add(Box.createVerticalGlue());