Add Capitals Quiz game and update Game page

- Introduced a new Capitals Quiz game with full functionality including question generation, scoring, and session management.
- Updated Game.svelte to include the Capitals Quiz in the game list with appropriate metadata.
- Enhanced the layout of the game grid for better responsiveness.
- Removed placeholder for the Capitals Quiz in the upcoming games section.
This commit is contained in:
sHa
2025-08-11 22:22:02 +03:00
parent 348617688c
commit 0eab81f0e2
5 changed files with 1604 additions and 4 deletions

View File

@@ -183,6 +183,9 @@
console.error("Error loading settings:", e);
}
}
// Load global stats and update them
loadGlobalStats();
}
await loadFlags();
@@ -513,6 +516,9 @@
// Save stats to localStorage
localStorage.setItem("flagQuizStats", JSON.stringify(gameStats));
// Update global stats
updateGlobalStats(isCorrect);
// Check for new achievements
if (achievementsComponent) {
achievementsComponent.checkAchievements();
@@ -569,6 +575,9 @@
// Save stats to localStorage
localStorage.setItem("flagQuizStats", JSON.stringify(gameStats));
// Update global stats (skipped question)
updateGlobalStats(null, true);
// Save session state
saveSessionState();
@@ -789,6 +798,60 @@
updateAchievementCount();
}
// Global statistics functions
function loadGlobalStats() {
const savedGlobalStats = localStorage.getItem("globalQuizStats");
if (savedGlobalStats) {
try {
const globalStats = JSON.parse(savedGlobalStats);
console.log("Loaded global stats:", globalStats);
} catch (e) {
console.error("Error loading global stats:", e);
}
}
}
function updateGlobalStats(isCorrect, isSkipped = false) {
let globalStats = {};
// Load existing global stats
const savedGlobalStats = localStorage.getItem("globalQuizStats");
if (savedGlobalStats) {
try {
globalStats = JSON.parse(savedGlobalStats);
} catch (e) {
console.error("Error parsing global stats:", e);
}
}
// Initialize stats structure if it doesn't exist
if (!globalStats.flagQuiz) {
globalStats.flagQuiz = { correct: 0, wrong: 0, total: 0, skipped: 0 };
}
if (!globalStats.overall) {
globalStats.overall = { correct: 0, wrong: 0, total: 0, skipped: 0 };
}
// Update flag quiz stats
globalStats.flagQuiz.total++;
globalStats.overall.total++;
if (isSkipped) {
globalStats.flagQuiz.skipped++;
globalStats.overall.skipped++;
} else if (isCorrect) {
globalStats.flagQuiz.correct++;
globalStats.overall.correct++;
} else {
globalStats.flagQuiz.wrong++;
globalStats.overall.wrong++;
}
// Save updated global stats
localStorage.setItem("globalQuizStats", JSON.stringify(globalStats));
console.log("Updated global stats:", globalStats);
}
// Sound functions
function playCorrectSound() {
if (!soundEnabled) return;