-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
741 lines (665 loc) · 30.4 KB
/
script.js
File metadata and controls
741 lines (665 loc) · 30.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
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
// Quiz Application State
let quizData = [];
let currentLevel = 1;
let currentQuestionIndex = 0;
let currentScore = 0;
let currentStreak = 0;
let levelQuestions = [];
let answeredQuestions = new Set();
let usedQuestionsInLevel = new Set();
let consecutiveWrongAnswers = 0;
let gameStats = {
totalQuestions: 0,
correctAnswers: 0,
levelScores: {},
levelStreaks: {},
levelCorrectAnswers: {}
};
// Questions per level configuration
const questionsPerLevel = {
1: 5,
2: 8,
3: 10,
4: 15
};
// Witty success messages for each level
const successMessages = {
1: [
"🏡 Cottage genius! You're building a solid foundation!",
"🎯 Bullseye! Your architectural instincts are spot on!",
"🌟 Rising star! You're mastering the basics beautifully!",
"💪 Foundation strong! You're crushing these fundamentals!",
"🎨 Artistic eye! You see architecture like a pro!",
"🚀 Taking off! Your knowledge is soaring!",
"💎 Diamond in the rough! You're shining bright!",
"🎪 Showstopper! You're putting on quite a performance!",
"🏆 Champion material! You're born for this!",
"✨ Magical touch! You make architecture look easy!",
"🎭 Star quality! You're stealing the architectural show!",
"🔥 On fire! You're absolutely unstoppable!",
"🎪 Center stage! All eyes are on your brilliance!",
"💫 Shooting star! You're lighting up the architectural sky!",
"🎨 Masterpiece! You're creating architectural art!",
"🌟 Supernova! You're exploding with knowledge!",
"🎯 Perfect aim! You never miss the mark!",
"💎 Precious talent! You're a rare architectural gem!",
"🚀 Rocket fuel! You're powered by pure genius!",
"🎪 Standing ovation! You deserve all the applause!"
],
2: [
"🏠 Mansion master! You're living in architectural luxury!",
"🎭 Regional royalty! You're ruling the architectural realm!",
"🌟 Cultural connoisseur! You understand architectural heritage!",
"💎 Regional gem! You're uncovering architectural treasures!",
"🎨 Heritage hero! You're preserving architectural beauty!",
"🚀 Regional rocket! You're exploring architectural frontiers!",
"💫 Cultural star! You're shining across architectural borders!",
"🎪 Regional show! You're the main attraction!",
"🏆 Heritage champion! You're defending architectural traditions!",
"✨ Cultural magic! You're weaving architectural stories!",
"🎭 Regional drama! You're starring in architectural excellence!",
"🔥 Cultural fire! You're burning with architectural passion!",
"💎 Regional diamond! You're cutting through architectural complexity!",
"🌟 Heritage hero! You're saving architectural legacies!",
"🎨 Cultural canvas! You're painting architectural masterpieces!",
"🚀 Regional explorer! You're discovering architectural wonders!",
"💫 Cultural comet! You're streaking through architectural history!",
"🎪 Regional festival! You're celebrating architectural diversity!",
"🏆 Cultural crown! You're wearing architectural royalty!",
"✨ Heritage harmony! You're orchestrating architectural beauty!",
"🎭 Regional legend! You're becoming an architectural icon!"
],
3: [
"🏘️ Modern marvel! You're ahead of the architectural curve!",
"🎯 Advanced ace! You're mastering complex concepts!",
"🌟 Sophisticated star! You're thinking like an architectural genius!",
"💎 Modern gem! You're cutting-edge in every way!",
"🎨 Contemporary creator! You're shaping architectural futures!",
"🚀 Advanced accelerator! You're pushing architectural boundaries!",
"💫 Sophisticated sparkle! You're radiating architectural brilliance!",
"🎪 Modern masterpiece! You're creating architectural innovation!",
"🏆 Advanced champion! You're conquering architectural complexity!",
"✨ Sophisticated sorcery! You're casting architectural spells!",
"🎭 Modern maestro! You're conducting architectural symphonies!",
"🔥 Advanced inferno! You're burning with architectural intensity!",
"💎 Contemporary crown! You're wearing architectural royalty!",
"🌟 Sophisticated supernova! You're exploding with architectural insight!",
"🎨 Modern magician! You're performing architectural miracles!",
"🚀 Advanced astronaut! You're exploring architectural galaxies!",
"💫 Sophisticated star! You're lighting up architectural skies!",
"🎪 Contemporary carnival! You're celebrating architectural innovation!",
"🏆 Advanced architect! You're building architectural dreams!",
"✨ Modern magic! You're creating architectural wonders!",
"🎭 Sophisticated sensation! You're the talk of architectural town!"
],
4: [
"🏙️ Skyline superstar! You're reaching architectural heights!",
"🎯 Elite expert! You're operating at architectural peak performance!",
"🌟 Luxury legend! You're living in architectural excellence!",
"💎 Elite diamond! You're the crown jewel of architecture!",
"🎨 Skyline artist! You're painting the architectural heavens!",
"🚀 Elite rocket! You're launching into architectural orbit!",
"💫 Luxury luminary! You're the brightest architectural star!",
"🎪 Elite extravaganza! You're throwing architectural parties!",
"🏆 Skyline champion! You're conquering architectural summits!",
"✨ Elite enchantment! You're casting architectural spells!",
"🎭 Luxury legend! You're starring in architectural blockbusters!",
"🔥 Elite inferno! You're burning with architectural passion!",
"💎 Skyline sapphire! You're precious architectural treasure!",
"🌟 Luxury luminary! You're illuminating architectural paths!",
"🎨 Elite artist! You're creating architectural masterpieces!",
"🚀 Skyline shuttle! You're traveling architectural galaxies!",
"💫 Elite energy! You're powering architectural innovation!",
"🎪 Luxury gala! You're hosting architectural celebrations!",
"🏆 Elite emperor! You're ruling the architectural empire!",
"✨ Skyline sorcery! You're performing architectural magic!",
"🎭 Luxury legend! You're becoming architectural royalty!"
]
};
// Motivational quotes for when users get 2 wrong answers in a row
const motivationalQuotes = {
1: [
"Every great architect was once a beginner. Keep building your foundation!",
"Mistakes are the stepping stones to architectural mastery. Keep going!",
"The best buildings are built on strong foundations. You're getting there!",
"Architecture is a journey, not a destination. You're on the right path!",
"Every wrong answer is a lesson learned. You're growing stronger!",
"The foundation of success is persistence. Don't give up now!",
"Great architects learn from every mistake. You're becoming great!",
"Your architectural journey is just beginning. Keep exploring!",
"Every expert was once a student. You're learning beautifully!",
"The path to mastery is paved with lessons. You're on track!",
"Architecture rewards those who persevere. Keep pushing forward!",
"Your foundation is getting stronger with every question!",
"Mistakes are just practice for perfection. You're practicing well!",
"Every building starts with a single brick. You're building something amazing!",
"The best architects never stop learning. You're a lifelong learner!",
"Your architectural instincts are developing. Trust the process!",
"Every challenge makes you stronger. You're getting stronger!",
"The foundation of excellence is built one step at a time!",
"You're not failing, you're learning. Keep learning!",
"Architecture is about persistence. You're showing great persistence!"
],
2: [
"Regional architecture teaches us about cultural diversity. Keep exploring!",
"Every region has its own architectural story. You're learning them all!",
"Cultural understanding comes with practice. You're practicing well!",
"Regional knowledge is architectural wisdom. You're gaining wisdom!",
"Every mistake is a step toward cultural understanding!",
"Architectural heritage is worth preserving. You're learning to preserve it!",
"Regional differences make architecture beautiful. You're seeing the beauty!",
"Cultural sensitivity is architectural intelligence. You're becoming intelligent!",
"Every region has architectural treasures. You're discovering them!",
"Regional knowledge is global wisdom. You're becoming globally wise!",
"Architectural diversity is cultural richness. You're experiencing richness!",
"Every culture has architectural lessons. You're learning them!",
"Regional understanding is architectural empathy. You're developing empathy!",
"Cultural knowledge is architectural power. You're gaining power!",
"Every region has architectural secrets. You're uncovering them!",
"Regional wisdom is architectural insight. You're gaining insight!",
"Cultural appreciation is architectural growth. You're growing!",
"Every mistake teaches cultural sensitivity. You're becoming sensitive!",
"Regional knowledge is architectural enlightenment. You're becoming enlightened!",
"Cultural understanding is architectural mastery. You're mastering it!"
],
3: [
"Advanced concepts challenge even the best architects. You're up for the challenge!",
"Complexity is the playground of architectural genius. You're playing well!",
"Advanced thinking comes with advanced practice. You're practicing advanced!",
"Sophisticated concepts require sophisticated minds. You have one!",
"Every complex problem has an elegant solution. You're finding them!",
"Advanced architecture is about pushing boundaries. You're pushing them!",
"Sophisticated thinking is architectural evolution. You're evolving!",
"Complex problems build complex solutions. You're building solutions!",
"Advanced knowledge is architectural power. You're gaining power!",
"Sophisticated understanding comes with time. You're using time wisely!",
"Complex concepts are architectural puzzles. You're solving puzzles!",
"Advanced thinking is architectural innovation. You're innovating!",
"Sophisticated problems require sophisticated approaches. You're approaching well!",
"Complex architecture is beautiful architecture. You're seeing beauty!",
"Advanced concepts are architectural frontiers. You're exploring frontiers!",
"Sophisticated thinking is architectural wisdom. You're gaining wisdom!",
"Complex problems are architectural opportunities. You're seizing opportunities!",
"Advanced knowledge is architectural insight. You're gaining insight!",
"Sophisticated understanding is architectural mastery. You're mastering it!",
"Complex concepts are architectural challenges. You're meeting challenges!"
],
4: [
"Elite architecture is for elite minds. You have an elite mind!",
"Skyline success comes to those who reach for it. You're reaching high!",
"Luxury architecture requires luxury thinking. You're thinking luxuriously!",
"Elite knowledge is architectural excellence. You're pursuing excellence!",
"Skyline heights are reached one step at a time. Keep climbing!",
"Luxury understanding comes with luxury effort. You're putting in effort!",
"Elite architecture is about elite standards. You're meeting standards!",
"Skyline success is architectural achievement. You're achieving!",
"Luxury knowledge is architectural power. You're gaining power!",
"Elite thinking is architectural innovation. You're innovating!",
"Skyline heights require skyline vision. You have vision!",
"Luxury architecture is about luxury details. You're noticing details!",
"Elite success comes to elite learners. You're an elite learner!",
"Skyline achievement is architectural mastery. You're mastering!",
"Luxury understanding is architectural wisdom. You're gaining wisdom!",
"Elite architecture is for elite architects. You're becoming elite!",
"Skyline heights are for skyline dreamers. You're dreaming big!",
"Luxury knowledge is architectural insight. You're gaining insight!",
"Elite thinking is architectural evolution. You're evolving!",
"Skyline success is architectural destiny. You're destined for success!"
]
};
// DOM Elements
const screens = {
welcome: document.getElementById('welcome-screen'),
quiz: document.getElementById('quiz-screen'),
levelComplete: document.getElementById('level-complete-screen'),
gameComplete: document.getElementById('game-complete-screen')
};
const elements = {
currentLevel: document.getElementById('current-level'),
currentQuestion: document.getElementById('current-question'),
currentScore: document.getElementById('current-score'),
currentStreak: document.getElementById('current-streak'),
progressFill: document.getElementById('progress-fill'),
categoryBadge: document.getElementById('category-badge'),
questionText: document.getElementById('question-text'),
optionA: document.getElementById('option-a'),
optionB: document.getElementById('option-b'),
optionC: document.getElementById('option-c'),
optionD: document.getElementById('option-d'),
nextBtn: document.getElementById('next-btn'),
feedbackOverlay: document.getElementById('feedback-overlay'),
feedbackIcon: document.getElementById('feedback-icon'),
feedbackTitle: document.getElementById('feedback-title'),
feedbackMessage: document.getElementById('feedback-message'),
feedbackStreak: document.getElementById('feedback-streak'),
feedbackScore: document.getElementById('feedback-score')
};
// Motivational messages for each level
const motivationMessages = {
1: [
"You're halfway through the Cottage Foundations! Your basics are strong!",
"Keep going! Your foundation is solid!"
],
2: [
"Halfway through Mansion Dreams! You're building up your knowledge!",
"Impressive! Your regional expertise is showing!"
],
3: [
"Modern Marvels halfway! You're mastering advanced concepts!",
"Great work! Your modern mind is shining!"
],
4: [
"Skyline Elite halfway! You're reaching new heights!",
"Elite performance! Your architectural instincts are top-notch!"
]
};
// Initialize the application
document.addEventListener('DOMContentLoaded', function() {
loadQuizData();
setupEventListeners();
// Always start fresh when page loads
resetQuizState();
// Load saved theme
const savedTheme = localStorage.getItem('selectedTheme');
if (savedTheme) {
changeTheme(savedTheme);
}
const closeBtn = document.getElementById('motivation-close-btn');
if (closeBtn) {
closeBtn.addEventListener('click', hideMotivationPopup);
}
const successCloseBtn = document.getElementById('success-close-btn');
if (successCloseBtn) {
successCloseBtn.addEventListener('click', hideSuccessPopup);
}
});
// Reset quiz state to ensure fresh start
function resetQuizState() {
currentLevel = 1;
currentQuestionIndex = 0;
currentScore = 0;
currentStreak = 0;
consecutiveWrongAnswers = 0;
levelQuestions = [];
answeredQuestions.clear();
usedQuestionsInLevel.clear();
gameStats = {
totalQuestions: 0,
correctAnswers: 0,
levelScores: {},
levelStreaks: {},
levelCorrectAnswers: {}
};
}
// Load quiz data from JSON file
async function loadQuizData() {
try {
const response = await fetch('corrected_level_1_questions.json');
quizData = await response.json();
console.log('Quiz data loaded:', quizData.length, 'questions');
} catch (error) {
console.error('Error loading quiz data:', error);
// Fallback data for testing
quizData = getFallbackData();
}
}
// Setup event listeners
function setupEventListeners() {
// Start button
document.getElementById('start-btn').addEventListener('click', startQuiz);
// Level item clicks
document.querySelectorAll('.level-item').forEach(item => {
item.addEventListener('click', () => {
const level = parseInt(item.dataset.level);
startQuizFromLevel(level);
});
});
// Theme buttons
document.querySelectorAll('.theme-btn').forEach(btn => {
btn.addEventListener('click', () => {
const theme = btn.dataset.theme;
changeTheme(theme);
});
});
// Option buttons
document.querySelectorAll('.option-btn').forEach(btn => {
btn.addEventListener('click', () => selectOption(btn.dataset.option));
});
// Next button
elements.nextBtn.addEventListener('click', nextQuestion);
// Level complete buttons
document.getElementById('next-level-btn').addEventListener('click', nextLevel);
document.getElementById('retry-level-btn').addEventListener('click', retryLevel);
// Game complete buttons
document.getElementById('play-again-btn').addEventListener('click', restartGame);
document.getElementById('share-btn').addEventListener('click', shareResults);
// Home button (will be added to HTML)
const homeBtn = document.getElementById('home-btn');
if (homeBtn) {
homeBtn.addEventListener('click', goHome);
}
}
// Start the quiz
function startQuiz() {
resetQuizState();
loadLevel(currentLevel);
showScreen('quiz');
}
// Start quiz from a specific level
function startQuizFromLevel(level) {
resetQuizState();
currentLevel = level;
loadLevel(currentLevel);
showScreen('quiz');
}
// Load a specific level
function loadLevel(level) {
currentLevel = level;
currentQuestionIndex = 0;
usedQuestionsInLevel.clear();
// Get questions for this level
const levelQuestionsPool = quizData.filter(q => q.level === level);
// Reset level-specific stats
gameStats.levelScores[level] = 0;
gameStats.levelStreaks[level] = 0;
gameStats.levelCorrectAnswers[level] = 0;
updateUI();
loadQuestion();
}
// Load current question
function loadQuestion() {
const maxQuestions = questionsPerLevel[currentLevel];
if (currentQuestionIndex >= maxQuestions) {
completeLevel();
return;
}
// Show motivation at halfway (after answering half the questions)
if (
currentQuestionIndex > 0 &&
currentQuestionIndex === Math.floor(maxQuestions / 2)
) {
showMotivationPopup(currentLevel);
}
// Get questions for this level that haven't been used yet
const levelQuestionsPool = quizData.filter(q => q.level === currentLevel);
const availableQuestions = levelQuestionsPool.filter(q => !usedQuestionsInLevel.has(q.id));
// If we've used all questions, reset the used questions set for fresh randomization
if (availableQuestions.length === 0) {
usedQuestionsInLevel.clear();
const resetAvailableQuestions = levelQuestionsPool;
levelQuestions = shuffleArray(resetAvailableQuestions).slice(0, maxQuestions);
} else {
// Select from available questions
levelQuestions = shuffleArray(availableQuestions).slice(0, maxQuestions);
}
const question = levelQuestions[currentQuestionIndex];
usedQuestionsInLevel.add(question.id);
// Update UI elements
elements.currentLevel.textContent = currentLevel;
elements.currentQuestion.textContent = `${currentQuestionIndex + 1}/${maxQuestions}`;
elements.categoryBadge.textContent = question.category;
elements.questionText.textContent = question.question;
elements.optionA.textContent = question.options.A;
elements.optionB.textContent = question.options.B;
elements.optionC.textContent = question.options.C;
elements.optionD.textContent = question.options.D;
// Reset option buttons
document.querySelectorAll('.option-btn').forEach(btn => {
btn.classList.remove('selected', 'correct', 'incorrect');
btn.disabled = false;
});
elements.nextBtn.disabled = true;
updateProgress();
}
// Handle option selection
function selectOption(selectedOption) {
const question = levelQuestions[currentQuestionIndex];
const correctOption = question.correct_answer;
const isCorrect = selectedOption === correctOption;
// Disable all options
document.querySelectorAll('.option-btn').forEach(btn => {
btn.disabled = true;
});
// Mark selected option
const selectedBtn = document.querySelector(`[data-option="${selectedOption}"]`);
selectedBtn.classList.add('selected');
// Mark correct/incorrect
if (isCorrect) {
selectedBtn.classList.add('correct');
currentScore += 10;
currentStreak++;
gameStats.correctAnswers++;
gameStats.levelScores[currentLevel] += 10;
gameStats.levelStreaks[currentLevel] = Math.max(gameStats.levelStreaks[currentLevel], currentStreak);
gameStats.levelCorrectAnswers[currentLevel]++;
// Reset consecutive wrong answers
consecutiveWrongAnswers = 0;
// Show success popup only at midway point (except for Level 1)
const maxQuestions = questionsPerLevel[currentLevel];
const isMidway = currentQuestionIndex === Math.floor(maxQuestions / 2) - 1;
if (isMidway && currentLevel > 1) {
showSuccessPopup(currentLevel);
}
} else {
selectedBtn.classList.add('incorrect');
// Reset streak on wrong answer but keep score
currentStreak = 0;
// Increment consecutive wrong answers
consecutiveWrongAnswers++;
// Show motivational quote only after 3+ consecutive wrong answers
if (consecutiveWrongAnswers >= 3) {
showMotivationalQuote(currentLevel);
}
// Show correct answer
const correctBtn = document.querySelector(`[data-option="${correctOption}"]`);
correctBtn.classList.add('correct');
}
gameStats.totalQuestions++;
answeredQuestions.add(question.id);
// Update UI
updateUI();
// Enable next button
elements.nextBtn.disabled = false;
}
// Move to next question
function nextQuestion() {
currentQuestionIndex++;
loadQuestion();
}
// Complete current level
function completeLevel() {
const levelScore = gameStats.levelScores[currentLevel];
const levelStreak = gameStats.levelStreaks[currentLevel];
const maxQuestions = questionsPerLevel[currentLevel];
const levelCorrectAnswers = gameStats.levelCorrectAnswers[currentLevel] || 0;
const accuracy = Math.round((levelCorrectAnswers / maxQuestions) * 100);
// Check if all questions were answered correctly
const allCorrect = levelCorrectAnswers === maxQuestions;
// Update level complete screen
document.getElementById('completed-level').textContent = currentLevel;
document.getElementById('level-score').textContent = levelScore;
document.getElementById('level-accuracy').textContent = `${accuracy}%`;
document.getElementById('level-streak').textContent = levelStreak;
// Update feedback message
const feedbackElement = document.getElementById('level-feedback');
if (allCorrect) {
feedbackElement.innerHTML = '<p>Perfect! You answered all questions correctly. Ready for the next challenge!</p>';
document.getElementById('next-level-btn').style.display = 'inline-block';
} else {
feedbackElement.innerHTML = '<p>Good effort! You need to answer all questions correctly to advance to the next level.</p>';
document.getElementById('next-level-btn').style.display = 'none';
}
showScreen('levelComplete');
}
// Move to next level
function nextLevel() {
if (currentLevel < 4) {
currentLevel++;
loadLevel(currentLevel);
showScreen('quiz');
} else {
completeGame();
}
}
// Retry current level
function retryLevel() {
loadLevel(currentLevel);
showScreen('quiz');
}
// Go home (back to welcome screen)
function goHome() {
resetQuizState();
showScreen('welcome');
}
// Complete the entire game
function completeGame() {
const totalScore = Object.values(gameStats.levelScores).reduce((sum, score) => sum + score, 0);
const overallAccuracy = Math.round((gameStats.correctAnswers / gameStats.totalQuestions) * 100);
document.getElementById('final-score').textContent = totalScore;
document.getElementById('final-accuracy').textContent = `${overallAccuracy}%`;
document.getElementById('final-questions').textContent = gameStats.totalQuestions;
showScreen('gameComplete');
}
// Restart the game
function restartGame() {
resetQuizState();
showScreen('welcome');
}
// Share results (placeholder)
function shareResults() {
const text = `I completed the Architecture Quiz with a score of ${document.getElementById('final-score').textContent} points! 🏛️`;
if (navigator.share) {
navigator.share({
title: 'Architecture Quiz Results',
text: text
});
} else {
// Fallback: copy to clipboard
navigator.clipboard.writeText(text).then(() => {
alert('Results copied to clipboard!');
});
}
}
// Update UI elements
function updateUI() {
elements.currentScore.textContent = currentScore;
elements.currentStreak.textContent = currentStreak;
}
// Update progress bar
function updateProgress() {
const maxQuestions = questionsPerLevel[currentLevel];
const progress = ((currentQuestionIndex + 1) / maxQuestions) * 100;
elements.progressFill.style.width = `${progress}%`;
}
// Show specific screen
function showScreen(screenName) {
Object.values(screens).forEach(screen => {
screen.classList.remove('active');
});
screens[screenName].classList.add('active');
}
// Utility function to shuffle array
function shuffleArray(array) {
const shuffled = [...array];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
}
// Fallback data in case JSON loading fails
function getFallbackData() {
return [
{
id: 1,
level: 1,
category: "Basic Definitions",
question: "What is the primary purpose of a 'facade' in architecture?",
options: {
"A": "To provide structural support",
"B": "To create an internal courtyard",
"C": "To serve as the front or main exterior elevation of a building",
"D": "To collect rainwater"
},
correct_answer: "C"
},
{
id: 2,
level: 1,
category: "Basic Definitions",
question: "A 'plinth' in architecture refers to what?",
options: {
"A": "A decorative ceiling element",
"B": "The lowest square part of the base of a column or pedestal",
"C": "A type of window frame",
"D": "A roof drainage system"
},
correct_answer: "B"
}
// Add more fallback questions as needed
];
}
// Show motivational pop-up
function showMotivationPopup(level) {
const popup = document.getElementById('motivation-popup');
const title = document.getElementById('motivation-title');
const message = document.getElementById('motivation-message');
const quoteElement = document.getElementById('motivational-quote');
// Pick a random message for variety
const messages = motivationMessages[level] || ["You're doing great! Keep going!"];
const msg = messages[Math.floor(Math.random() * messages.length)];
title.textContent = "You're halfway there!";
message.textContent = msg;
quoteElement.style.display = 'none';
popup.classList.add('show');
}
// Hide motivational pop-up
function hideMotivationPopup() {
document.getElementById('motivation-popup').classList.remove('show');
}
// Show success pop-up
function showSuccessPopup(level) {
const popup = document.getElementById('success-popup');
const title = document.getElementById('success-title');
const message = document.getElementById('success-message');
// Pick a random message for variety
const messages = successMessages[level] || ["You're doing great! Keep going!"];
const msg = messages[Math.floor(Math.random() * messages.length)];
title.textContent = "Congratulations!";
message.textContent = msg;
popup.classList.add('show');
}
// Hide success pop-up
function hideSuccessPopup() {
document.getElementById('success-popup').classList.remove('show');
}
// Show motivational quote
function showMotivationalQuote(level) {
const popup = document.getElementById('motivation-popup');
const title = document.getElementById('motivation-title');
const message = document.getElementById('motivation-message');
const quoteElement = document.getElementById('motivational-quote');
const quotes = motivationalQuotes[level] || ["Keep learning and growing!"];
const quote = quotes[Math.floor(Math.random() * quotes.length)];
title.textContent = "Don't Give Up!";
message.textContent = "Remember, every great architect faced challenges!";
quoteElement.textContent = quote;
quoteElement.style.display = 'block';
popup.classList.add('show');
}
// Change theme
function changeTheme(theme) {
// Remove all theme classes
document.body.classList.remove('ocean-theme', 'sunset-theme', 'forest-theme');
// Add new theme class
if (theme !== 'default') {
document.body.classList.add(theme + '-theme');
}
// Update active button
document.querySelectorAll('.theme-btn').forEach(btn => {
btn.classList.remove('active');
});
document.querySelector(`[data-theme="${theme}"]`).classList.add('active');
// Save theme preference
localStorage.setItem('selectedTheme', theme);
}