mirror of
https://github.com/shadoll/sLogos.git
synced 2025-12-20 11:32:01 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user