-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
556 lines (510 loc) · 28.4 KB
/
Copy pathindex.html
File metadata and controls
556 lines (510 loc) · 28.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Vocab Master - Network Edition</title>
<style>
:root { --primary: #6366f1; --bg: #0f172a; --card: #1e293b; --text: #f8fafc; --accent: #f472b6; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); user-select: none; padding: 20px; min-height: 100vh; }
.container { display: grid; grid-template-columns: 1fr 350px; gap: 20px; max-width: 1400px; margin: 0 auto; }
#game-container { background: var(--card); padding: 40px; border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,0.4); border: 1px solid #334155; position: relative; }
#leaderboard-container { background: var(--card); padding: 25px; border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,0.4); border: 1px solid #334155; max-height: 90vh; overflow-y: auto; position: sticky; top: 20px; }
.lvl-indicator { color: var(--accent); font-weight: bold; font-size: 1.1rem; margin-bottom: 10px; text-align: center; }
.sentence { font-size: 1.5rem; margin: 20px 0; min-height: 80px; line-height: 1.4; color: #e2e8f0; text-align: center; }
input { background: #0f172a; border: 2px solid #334155; color: white; font-size: 16px; padding: 12px; width: 100%; border-radius: 10px; text-align: center; outline: none; -webkit-appearance: none; }
input:focus { border-color: var(--primary); }
#feedback-box { display: none; background: #064e3b; padding: 20px; border-radius: 12px; margin-top: 20px; text-align: right; border-right: 5px solid #10b981; direction: rtl; }
#error-msg { color: #ef4444; font-size: 0.9rem; margin-top: 10px; height: 20px; font-weight: bold; text-align: center; }
.btn { border: none; color: white; padding: 12px 25px; border-radius: 8px; cursor: pointer; font-weight: bold; margin: 5px; transition: 0.2s; min-height: 44px; font-size: 1rem; }
.btn:hover { opacity: 0.9; transform: scale(1.02); }
.btn:active { transform: scale(0.95); }
.btn-next { background: var(--primary); }
.btn-hint { background: #475569; font-size: 0.8rem; border: 1px solid #64748b; }
.stats { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 20px; color: #64748b; }
.scrambled { letter-spacing: 5px; color: #fbbf24; font-size: 1.8rem; font-weight: bold; margin: 10px 0; text-align: center; }
.highlight { color: var(--accent); font-weight: bold; }
#hint-display { margin-top: 10px; color: #fbbf24; font-family: monospace; font-size: 1.2rem; min-height: 1.5rem; text-align: center; }
#timer-display { font-size: 1rem; font-weight: bold; text-align: center; margin-top: 8px; }
#timer-bar-wrap { height: 6px; background: #1e293b; border-radius: 4px; margin-top: 6px; overflow: hidden; }
#timer-bar { height: 100%; border-radius: 4px; width: 100%; transition: width 0.2s linear, background 0.5s; background: #10b981; }
#points-preview { font-size: 0.8rem; color: #94a3b8; text-align: center; margin-top: 4px; }
#time-expired-msg { display: none; background: rgba(239,68,68,0.15); border: 2px solid #ef4444; border-radius: 12px; padding: 14px 20px; margin-top: 14px; text-align: center; color: #fca5a5; font-weight: bold; font-size: 1rem; }
#game-container.time-up { background: linear-gradient(160deg, #2d0a0a 0%, #1e293b 60%); border-color: #ef4444; transition: background 0.5s, border-color 0.3s; }
#cheat-progress { height: 4px; background: var(--accent); width: 0%; position: absolute; top: 0; left: 0; transition: width 0.1s; border-radius: 20px 20px 0 0; }
/* Leaderboard Styles */
.leaderboard-header { text-align: center; margin-bottom: 20px; }
.leaderboard-title { color: var(--accent); font-size: 1.5rem; font-weight: bold; margin-bottom: 5px; }
.network-status { color: #10b981; font-size: 0.85rem; font-weight: bold; }
.leaderboard-entry { display: flex; justify-content: space-between; align-items: center; padding: 12px; margin: 8px 0; background: #0f172a; border-radius: 10px; border-left: 4px solid var(--primary); transition: 0.2s; animation: slideIn 0.3s ease-out; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: translateX(0); } }
.leaderboard-entry:hover { transform: translateX(5px); background: #1a2332; }
.leaderboard-entry:first-child { border-left-color: #fbbf24; background: linear-gradient(90deg, #78350f 0%, #0f172a 30%); }
.leaderboard-entry:nth-child(2) { border-left-color: #9ca3af; background: linear-gradient(90deg, #374151 0%, #0f172a 30%); }
.leaderboard-entry:nth-child(3) { border-left-color: #d97706; background: linear-gradient(90deg, #78350f 0%, #0f172a 30%); }
.rank { color: var(--accent); font-weight: bold; margin-right: 10px; min-width: 35px; font-size: 1rem; }
.player-name { font-weight: bold; font-size: 0.95rem; }
.player-score { color: var(--accent); font-weight: bold; font-size: 1.1rem; }
.empty-leaderboard { text-align: center; color: #64748b; padding: 40px 20px; }
@media (max-width: 1000px) {
body { padding: 10px; }
.container { grid-template-columns: 1fr; gap: 15px; }
#leaderboard-container { max-height: 400px; position: static; }
#game-container { padding: 20px; }
.sentence { font-size: 1.2rem; min-height: 60px; }
.scrambled { font-size: 1.4rem; letter-spacing: 3px; }
input { font-size: 1.2rem; padding: 15px; width: 100%; }
.stats { font-size: 0.85rem; }
.lvl-indicator { font-size: 1rem; }
.btn { padding: 15px 20px; font-size: 1rem; }
#hint-display { font-size: 1rem; }
}
@media (max-width: 600px) {
body { padding: 5px; }
#game-container { padding: 15px; }
#leaderboard-container { padding: 15px; }
.sentence { font-size: 1rem; }
.scrambled { font-size: 1.2rem; }
input { font-size: 1.1rem; padding: 12px; }
.leaderboard-title { font-size: 1.2rem; }
.leaderboard-entry { padding: 10px; }
.player-name { font-size: 0.85rem; }
.rank { font-size: 0.9rem; min-width: 30px; }
}
</style>
</head>
<body>
<div class="container">
<!-- GAME SECTION -->
<div id="game-container">
<div id="cheat-progress"></div>
<div class="stats">
<span>SCORE: <span id="score" style="color:white; font-weight:bold; font-size:1.1rem;">0</span></span>
<div id="level-title" class="lvl-indicator">LEVEL 1</div>
<span>PROGRESS: <span id="progress">1/20</span></span>
</div>
<div id="question-area">
<div class="sentence" id="display-text">Loading...</div>
<div id="extra-hint" class="scrambled"></div>
<input type="text" id="user-input" autocomplete="off" placeholder="Type here...">
<div id="error-msg"></div>
<div id="hint-display"></div>
<div id="timer-display">⏱ <span id="timer-text">30.0s</span></div>
<div id="timer-bar-wrap"><div id="timer-bar"></div></div>
<div id="points-preview">⭐ <span id="pts-preview">100</span> pts if correct now</div>
<div id="time-expired-msg">⏰ Time's up! You won't earn points for this one.<br><button class="btn" style="background:#ef4444; margin-top:10px;" onclick="skipQuestion()">Skip →</button></div>
<div style="margin-top: 15px; text-align: center;">
<button id="hint-btn" class="btn btn-hint" onclick="getLetterHint()" style="padding: 10px 28px; line-height: 1.4;">
<div style="font-size: 0.85rem; opacity: 0.85;">💡 Hint</div>
<div id="hint-cost-display" style="font-size: 1.3rem; font-weight: bold; color: #fbbf24;">-10 pts</div>
</button>
</div>
</div>
<div id="feedback-box">
<div style="color: #10b981; font-weight: bold; margin-bottom: 8px; font-size: 1.1rem;">Correct! 🎉</div>
<div id="explanation-text" style="font-size: 1.2rem; line-height: 1.5;"></div>
<button class="btn btn-next" onclick="nextQuestion()">Next word →</button>
</div>
</div>
<!-- LEADERBOARD SECTION -->
<div id="leaderboard-container">
<div class="leaderboard-header">
<div class="leaderboard-title">🏆 LEADERBOARD</div>
<div id="network-status" class="network-status">🌐 LIVE • Syncing</div>
</div>
<div id="leaderboard-list"></div>
</div>
</div>
<script>
// All sentences grouped by word — one is picked at random each game
const wordBank = [
{w: "distribution", h: "להפיץ", sentences: [
"The _______ of food was organized by the charity.",
"The _______ of homework was unfair — some students got twice as much.",
"Equal _______ of resources is important in a fair society."
]},
{w: "program", h: "תוכנית", sentences: [
"I need to follow the training _______.",
"The after-school _______ helps students with their homework.",
"She signed up for a fitness _______ at the gym."
]},
{w: "compulsive", h: "כפייתי, כפייתית, כפייתיים, כפייתיות", sentences: [
"His _______ behavior made it hard to stop.",
"She is a _______ liar who can't seem to tell the truth.",
"_______ eating can be a sign of emotional stress."
]},
{w: "implemented", h: "יהיו מיושמות", sentences: [
"The new rules will be _______ next week.",
"The safety measures were _______ after the accident.",
"The plan was finally _______ after months of planning."
]},
{w: "questionnaire", h: "שאלון, שאלונים", sentences: [
"Please complete this _______ for the survey.",
"The doctor asked her to fill out a health _______ before the appointment.",
"We sent a _______ to all students to understand their needs."
]},
{w: "sergeant", h: "דרגה בצבא", sentences: [
"The _______ led the soldiers to the base.",
"The _______ shouted orders across the training field.",
"He worked hard for years to earn the rank of _______."
]},
{w: "implications", h: "השלכה, השלכות", sentences: [
"We must consider the _______ of our actions.",
"The _______ of the new law are still not fully understood.",
"His decision had serious _______ for the whole team."
]},
{w: "programs", h: "תוכניות", sentences: [
"The computer runs several _______ at once.",
"The school offers special _______ for gifted students.",
"Many support _______ were cut due to budget issues."
]},
{w: "addiction", h: "התמכרות", sentences: [
"He is fighting a dangerous _______.",
"Screen _______ is becoming a serious problem for teenagers.",
"Overcoming a _______ takes a lot of courage and support."
]},
{w: "immediate", h: "מיידית", sentences: [
"This emergency requires an _______ response.",
"The doctor said she needed _______ treatment.",
"The announcement had an _______ effect on the crowd."
]},
{w: "proud", h: "גאה", sentences: [
"Her parents were so _______ of her.",
"He felt _______ after finishing the race.",
"Be _______ of who you are, no matter what others say."
]},
{w: "educational", h: "חינוכי", sentences: [
"The museum offers an _______ experience.",
"The documentary was both entertaining and _______.",
"They visited the science center for an _______ field trip."
]},
{w: "lead", h: "להוביל", sentences: [
"A good captain should _______ his team.",
"She was chosen to _______ the school project.",
"It takes confidence to _______ a group of people."
]},
{w: "responsibility", h: "אחריות", sentences: [
"Taking care of the pet is your _______.",
"It is your _______ to hand in your homework on time.",
"With great power comes great _______."
]},
{w: "ponder", h: "לתהות", sentences: [
"I need some time to _______ the question.",
"She sat quietly to _______ her next move.",
"Let's _______ this idea before making a decision."
]},
{w: "journey", h: "מסע", sentences: [
"The _______ to the mountain took three days.",
"Learning a new language is a long _______.",
"The _______ home felt much shorter than the way there."
]},
{w: "balance", h: "שיווי משקל", sentences: [
"It is hard to keep your _______ on ice.",
"You need to find a _______ between work and rest.",
"The gymnast lost her _______ and fell off the beam."
]},
{w: "dust", h: "אבק.לאבק", sentences: [
"There is a lot of _______ on the old books.",
"She used a cloth to _______ the furniture every morning.",
"A cloud of _______ rose as the truck drove down the dirt road."
]},
{w: "bear in mind", h: "לקחת בחשבון", sentences: [
"Please _______ that the shop is closed.",
"_______ that not everyone speaks English as a first language.",
"You should _______ that the deadline is tomorrow."
]},
{w: "seed", h: "זרע", sentences: [
"The tree grew from a tiny _______.",
"She planted a _______ in the garden and watered it every day.",
"One small _______ of doubt can grow into a big problem."
]}
];
// Pick one random sentence per word, then shuffle the 20 into a random order
function buildVocabulary() {
const picked = wordBank.map(entry => ({
w: entry.w,
h: entry.h,
s: entry.sentences[Math.floor(Math.random() * entry.sentences.length)]
}));
// Fisher-Yates shuffle
for (let i = picked.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[picked[i], picked[j]] = [picked[j], picked[i]];
}
return picked;
}
const vocabulary = buildVocabulary();
let currentIdx = 0;
let score = 0;
let hintsUsed = 0;
let spaceTimer = null;
let questionStartTime = null;
let timerInterval = null;
let timeExpired = false;
const MAX_TIME = 30; // seconds — full time = max points
const MAX_POINTS = 100;
const MIN_POINTS = 10;
function getTimedPoints(elapsedSeconds, hintsUsed) {
// Linear scale: 100 pts at 0s → 10 pts at 30s
const timeFraction = Math.min(elapsedSeconds, MAX_TIME) / MAX_TIME;
const base = Math.round(MAX_POINTS - (MAX_POINTS - MIN_POINTS) * timeFraction);
// Each hint deducts 10 pts
return Math.max(MIN_POINTS, base - hintsUsed * 10);
}
function startTimer() {
clearInterval(timerInterval);
timeExpired = false;
document.getElementById('game-container').classList.remove('time-up');
document.getElementById('time-expired-msg').style.display = 'none';
questionStartTime = Date.now();
timerInterval = setInterval(() => {
const elapsed = (Date.now() - questionStartTime) / 1000;
const remaining = Math.max(0, MAX_TIME - elapsed);
const pct = (remaining / MAX_TIME) * 100;
const pts = getTimedPoints(elapsed, hintsUsed);
document.getElementById('timer-text').innerText = remaining.toFixed(1) + 's';
document.getElementById('pts-preview').innerText = pts;
const bar = document.getElementById('timer-bar');
bar.style.width = pct + '%';
// Colour: green → yellow → red
if (pct > 60) bar.style.background = '#10b981';
else if (pct > 30) bar.style.background = '#fbbf24';
else bar.style.background = '#ef4444';
if (elapsed >= MAX_TIME && !timeExpired) {
timeExpired = true;
clearInterval(timerInterval);
document.getElementById('timer-text').innerText = '0.0s';
document.getElementById('pts-preview').innerText = '0';
document.getElementById('game-container').classList.add('time-up');
document.getElementById('time-expired-msg').style.display = 'block';
}
}, 100);
}
// API Functions
async function getLeaderboard() {
const response = await fetch('/api/leaderboard');
return await response.json();
}
async function addToLeaderboard(name, score) {
const response = await fetch('/api/leaderboard', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, score })
});
return await response.json();
}
function updateLeaderboardDisplay(leaderboard) {
const listEl = document.getElementById('leaderboard-list');
if (!leaderboard || leaderboard.length === 0) {
listEl.innerHTML = '<div class="empty-leaderboard">🎮<br><br>No scores yet!<br>Be the first!</div>';
} else {
const medals = ['🥇', '🥈', '🥉'];
listEl.innerHTML = leaderboard.map((entry, idx) => `
<div class="leaderboard-entry" style="animation-delay: ${idx * 0.05}s">
<div style="display: flex; align-items: center;">
<span class="rank">${medals[idx] || `#${idx + 1}`}</span>
<div>
<div class="player-name">${entry.name}</div>
<div style="font-size: 0.7rem; color: #64748b;">${entry.date}</div>
</div>
</div>
<div class="player-score">${entry.score}</div>
</div>
`).join('');
}
}
// Auto-refresh leaderboard every 2 seconds
setInterval(async () => {
const leaderboard = await getLeaderboard();
updateLeaderboardDisplay(leaderboard);
}, 2000);
// Initial load
(async () => {
const leaderboard = await getLeaderboard();
updateLeaderboardDisplay(leaderboard);
})();
function scramble(word) {
let clean = word.replace(/\s/g, '');
return clean.split('').sort(() => Math.random() - 0.5).join('').toUpperCase();
}
function loadQuestion() {
const q = vocabulary[currentIdx];
hintsUsed = 0;
document.getElementById('feedback-box').style.display = "none";
document.getElementById('question-area').style.display = "block";
document.getElementById('time-expired-msg').style.display = 'none';
document.getElementById('game-container').classList.remove('time-up');
document.getElementById('user-input').value = "";
document.getElementById('hint-display').innerText = "";
document.getElementById('error-msg').innerText = "";
document.getElementById('progress').innerText = `${currentIdx + 1}/${vocabulary.length}`;
document.getElementById('hint-btn').disabled = false;
document.getElementById('hint-cost-display').innerText = '-1 pt';
if (currentIdx < 7) {
document.getElementById('level-title').innerText = "LEVEL 1: SCRAMBLE";
document.getElementById('display-text').innerHTML = q.s.replace("_______", "<span class='highlight'>_______</span>");
document.getElementById('extra-hint').innerText = scramble(q.w);
} else if (currentIdx < 14) {
document.getElementById('level-title').innerText = "LEVEL 2: CONTEXT";
document.getElementById('display-text').innerHTML = q.s.replace("_______", "<span class='highlight'>_______</span>");
document.getElementById('extra-hint').innerText = "";
} else {
document.getElementById('level-title').innerText = "LEVEL 3: TRANSLATE";
document.getElementById('display-text').innerHTML = `Translate to English: <br><span class="highlight">${q.h}</span>`;
document.getElementById('extra-hint').innerText = "";
}
document.getElementById('user-input').focus();
startTimer();
}
function checkAnswer() {
const userInput = document.getElementById('user-input').value.toLowerCase().trim().replace(/\s+/g, ' ');
const correctAnswer = vocabulary[currentIdx].w.toLowerCase().trim();
if (userInput === correctAnswer) {
showFeedback();
} else {
document.getElementById('error-msg').innerText = "❌ Try again!";
document.getElementById('user-input').style.borderColor = "#ef4444";
setTimeout(() => {
document.getElementById('user-input').style.borderColor = "#334155";
document.getElementById('error-msg').innerText = "";
}, 1500);
}
}
function showFeedback() {
clearInterval(timerInterval);
const elapsed = (Date.now() - questionStartTime) / 1000;
const earned = timeExpired ? 0 : getTimedPoints(elapsed, hintsUsed);
document.getElementById('question-area').style.display = "none";
document.getElementById('feedback-box').style.display = "block";
document.getElementById('game-container').classList.remove('time-up');
score += earned;
document.getElementById('score').innerText = score;
const pointsNote = timeExpired
? `<div style="color:#ef4444; font-size:0.9rem; margin-top:6px;">⏰ No points — time ran out</div>`
: `<div style="color:#10b981; font-size:0.9rem; margin-top:6px;">+${earned} pts in ${elapsed.toFixed(1)}s</div>`;
document.getElementById('explanation-text').innerHTML =
`<b>${vocabulary[currentIdx].w}</b> = ${vocabulary[currentIdx].h}` + pointsNote;
}
function skipQuestion() {
clearInterval(timerInterval);
document.getElementById('game-container').classList.remove('time-up');
currentIdx++;
if (currentIdx < vocabulary.length) {
loadQuestion();
} else {
document.getElementById('game-container').innerHTML = `
<div style="text-align: center; padding: 40px;">
<h1 style="color: var(--accent); margin-bottom: 20px;">🏆 COMPLETE!</h1>
<p style="font-size: 2.5rem; color: var(--accent); margin: 20px 0; font-weight: bold;">${score}</p>
<input type="text" id="name-input" placeholder="Your name" style="width: 60%; margin: 20px 0;" maxlength="20" value="">
<br>
<button class="btn btn-next" onclick="submitScore()" style="font-size: 1.1rem; padding: 15px 30px;">💾 SUBMIT</button>
<button class="btn btn-hint" onclick="location.reload()">🔄 PLAY AGAIN</button>
</div>
`;
document.getElementById('name-input').focus();
document.getElementById('name-input').addEventListener('keypress', (e) => {
if (e.key === 'Enter') submitScore();
});
}
}
function getLetterHint() {
const wordLen = vocabulary[currentIdx].w.replace(/\s/g, '').length;
if (hintsUsed >= wordLen) return;
const cost = Math.pow(2, hintsUsed); // 1, 2, 4, 8, 16, ...
hintsUsed++;
score = Math.max(0, score - cost);
document.getElementById('score').innerText = score;
document.getElementById('hint-display').innerText = `💡 ${vocabulary[currentIdx].w.substring(0, hintsUsed)}...`;
const nextCost = Math.pow(2, hintsUsed);
const remaining = wordLen - hintsUsed;
if (remaining > 0) {
document.getElementById('hint-cost-display').innerText = `-${nextCost} ${nextCost === 1 ? 'pt' : 'pts'}`;
document.getElementById('hint-btn').disabled = false;
} else {
document.getElementById('hint-cost-display').innerText = 'Full';
document.getElementById('hint-btn').disabled = true;
}
const elapsed = (Date.now() - questionStartTime) / 1000;
document.getElementById('pts-preview').innerText = getTimedPoints(elapsed, hintsUsed);
}
function nextQuestion() {
currentIdx++;
if (currentIdx < vocabulary.length) {
loadQuestion();
} else {
document.getElementById('game-container').innerHTML = `
<div style="text-align: center; padding: 40px;">
<h1 style="color: var(--accent); margin-bottom: 20px;">🏆 COMPLETE!</h1>
<p style="font-size: 2.5rem; color: var(--accent); margin: 20px 0; font-weight: bold;">${score}</p>
<input type="text" id="name-input" placeholder="Your name" style="width: 60%; margin: 20px 0;" maxlength="20" value="">
<br>
<button class="btn btn-next" onclick="submitScore()" style="font-size: 1.1rem; padding: 15px 30px;">💾 SUBMIT</button>
<button class="btn btn-hint" onclick="location.reload()">🔄 PLAY AGAIN</button>
</div>
`;
document.getElementById('name-input').focus();
document.getElementById('name-input').addEventListener('keypress', (e) => {
if (e.key === 'Enter') submitScore();
});
}
}
async function submitScore() {
const nameInput = document.getElementById('name-input');
const name = nameInput.value.trim() || 'Anonymous';
await addToLeaderboard(name, score);
document.getElementById('game-container').innerHTML = `
<div style="text-align: center; padding: 40px;">
<h1 style="color: #10b981; margin-bottom: 20px;">✅ SAVED!</h1>
<div style="font-size: 1.8rem; font-weight: bold; color: white; margin: 20px 0;">${name}</div>
<div style="font-size: 2.5rem; font-weight: bold; color: var(--accent); margin: 20px 0;">${score} pts</div>
<p style="color: #64748b; margin: 20px 0;">Check the leaderboard →</p>
<button class="btn btn-next" onclick="location.reload()" style="font-size: 1.1rem; padding: 15px 30px;">🔄 PLAY AGAIN</button>
</div>
`;
}
document.getElementById('user-input').addEventListener('keypress', (e) => {
if (e.key === 'Enter') checkAnswer();
});
// Backslash cheat
window.addEventListener('keydown', (e) => {
if (e.code === 'Backslash' && !spaceTimer && document.getElementById('question-area').style.display !== "none") {
e.preventDefault();
let start = Date.now();
spaceTimer = setInterval(() => {
let elapsed = Date.now() - start;
document.getElementById('cheat-progress').style.width = Math.min((elapsed/2000)*100, 100) + "%";
if (elapsed >= 2000) {
clearInterval(spaceTimer);
document.getElementById('user-input').value = vocabulary[currentIdx].w;
checkAnswer();
}
}, 50);
}
// Shift+1/2/3 level switching
if (e.shiftKey && document.getElementById('question-area').style.display !== "none") {
if (e.key === '1' || e.key === '!') {
currentIdx = 0;
loadQuestion();
} else if (e.key === '2' || e.key === '@') {
currentIdx = 7;
loadQuestion();
} else if (e.key === '3' || e.key === '#') {
currentIdx = 14;
loadQuestion();
}
}
});
window.addEventListener('keyup', (e) => {
if (e.code === 'Backslash') {
clearInterval(spaceTimer);
spaceTimer = null;
document.getElementById('cheat-progress').style.width = "0%";
}
});
// Start game
loadQuestion();
</script>
</body>
</html>