Initial commit: Modernes Harry Potter Escape Quiz Portal (FastAPI & MariaDB)

This commit is contained in:
kobold-ai
2026-09-21 11:29:18 +02:00
commit c3a21369ef
50 changed files with 3346 additions and 0 deletions
BIN
View File
Binary file not shown.
+769
View File
@@ -0,0 +1,769 @@
:root {
--bg-dark: #0b0b16;
--bg-card: rgba(22, 24, 44, 0.85);
--bg-card-hover: rgba(30, 33, 60, 0.95);
--gold: #c9a86a;
--gold-bright: #ffd700;
--gold-soft: #e6c98f;
--text-main: #f5f5f7;
--text-muted: #b8b8cc;
--parchment: #f6eedb;
--wax-red: #8b0000;
--success: #2ecc71;
--danger: #e74c3c;
--warning: #f39c12;
--border-gold: rgba(201, 168, 106, 0.35);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: var(--bg-dark);
background-image:
radial-gradient(circle at 20% 20%, rgba(201, 168, 106, 0.08) 0%, transparent 40%),
radial-gradient(circle at 80% 80%, rgba(116, 0, 1, 0.08) 0%, transparent 50%);
color: var(--text-main);
font-family: "Georgia", "Cinzel", "Times New Roman", serif;
min-height: 100vh;
display: flex;
flex-direction: column;
overflow-x: hidden;
}
/* Header Audio & Navigation Bar */
.audio-control-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
background: rgba(11, 11, 22, 0.7);
backdrop-filter: blur(10px);
border-bottom: 1px solid var(--border-gold);
position: sticky;
top: 0;
z-index: 100;
}
.audio-btn {
background: rgba(201, 168, 106, 0.15);
border: 1px solid var(--gold);
color: var(--gold-soft);
padding: 6px 14px;
border-radius: 20px;
cursor: pointer;
font-size: 0.85rem;
display: flex;
align-items: center;
gap: 6px;
transition: all 0.2s ease;
}
.audio-btn:hover {
background: var(--gold);
color: #000;
box-shadow: 0 0 10px rgba(201, 168, 106, 0.5);
}
.nav-links {
display: flex;
gap: 15px;
align-items: center;
}
.nav-link {
color: var(--text-muted);
text-decoration: none;
font-size: 0.9rem;
transition: color 0.2s ease;
}
.nav-link:hover {
color: var(--gold);
text-shadow: 0 0 5px rgba(201, 168, 106, 0.5);
}
/* Container */
.container {
flex: 1;
max-width: 800px;
width: 92%;
margin: 30px auto;
}
.admin-wrapper {
max-width: 950px;
width: 95%;
margin: 30px auto;
}
/* Titles */
.glow-title {
color: var(--gold);
font-size: 2rem;
text-align: center;
letter-spacing: 1px;
text-shadow: 0 0 12px rgba(201, 168, 106, 0.4);
margin-bottom: 8px;
}
.subtitle {
text-align: center;
color: var(--text-muted);
font-style: italic;
margin-bottom: 25px;
}
/* Card Styling */
.card {
background: var(--bg-card);
border: 1px solid var(--border-gold);
border-radius: 12px;
padding: 30px;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
backdrop-filter: blur(8px);
margin-bottom: 25px;
transition: border-color 0.3s ease;
}
.card:hover {
border-color: rgba(201, 168, 106, 0.6);
}
/* Envelope Intro Animation */
.intro-envelope {
position: relative;
width: 240px;
height: 160px;
margin: 20px auto 35px;
perspective: 800px;
}
.envelope-body {
width: 100%;
height: 100%;
background: #e8dbc3;
border-radius: 6px;
border: 2px solid var(--gold);
position: relative;
box-shadow: 0 10px 25px rgba(0,0,0,0.6);
}
.envelope-flap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #d8c9ad;
clip-path: polygon(0 0, 50% 55%, 100% 0);
transform-origin: top;
transition: transform 0.9s cubic-bezier(0.4, 0, 0.2, 1);
z-index: 3;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.wax-seal {
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%, -50%);
width: 44px;
height: 44px;
background: radial-gradient(circle, #a81c1c 40%, #680d0d 100%);
border-radius: 50%;
border: 2px solid #500606;
color: #ffd700;
font-weight: bold;
font-size: 1.4rem;
display: flex;
align-items: center;
justify-content: center;
z-index: 4;
box-shadow: 0 4px 8px rgba(0,0,0,0.5);
transition: opacity 0.5s ease;
}
.letter-preview {
position: absolute;
bottom: 5px;
left: 50%;
transform: translateX(-50%);
width: 88%;
height: 80%;
background: #fffdfa;
border: 1px solid #d4c5a9;
border-radius: 4px;
padding: 10px;
z-index: 2;
transition: transform 0.8s ease 0.3s;
}
.letter-text {
font-size: 0.7rem;
color: #443;
text-align: center;
font-style: italic;
}
/* Open Animation */
.envelope-opened .envelope-flap {
transform: rotateX(180deg);
z-index: 1;
}
.envelope-opened .wax-seal {
opacity: 0;
pointer-events: none;
}
.envelope-opened .letter-preview {
transform: translate(-50%, -40px);
}
.intro-content {
text-align: center;
}
.intro-text {
font-size: 1.15rem;
line-height: 1.6;
margin-bottom: 25px;
color: var(--text-muted);
}
/* Buttons */
.btn {
display: inline-block;
padding: 12px 24px;
border-radius: 8px;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
text-decoration: none;
transition: all 0.2s ease;
border: none;
font-family: inherit;
}
.btn-primary {
background: linear-gradient(135deg, var(--gold) 0%, #b8860b 100%);
color: #0c0d14;
box-shadow: 0 4px 15px rgba(201, 168, 106, 0.3);
}
.btn-primary:hover {
background: linear-gradient(135deg, #ffd700 0%, var(--gold) 100%);
box-shadow: 0 6px 20px rgba(201, 168, 106, 0.5);
transform: translateY(-2px);
}
.btn-secondary {
background: rgba(255, 255, 255, 0.08);
color: var(--gold-soft);
border: 1px solid var(--gold);
}
.btn-secondary:hover {
background: rgba(201, 168, 106, 0.2);
}
.btn-danger {
background: rgba(231, 76, 60, 0.2);
color: #ff7675;
border: 1px solid var(--danger);
}
.btn-danger:hover {
background: var(--danger);
color: #fff;
}
.btn-success {
background: rgba(46, 204, 113, 0.2);
color: #55efc4;
border: 1px solid var(--success);
}
.btn-success:hover {
background: var(--success);
color: #000;
}
.btn-large {
font-size: 1.15rem;
padding: 14px 32px;
}
.btn-sm {
font-size: 0.85rem;
padding: 6px 12px;
}
.btn-group {
display: flex;
gap: 12px;
justify-content: center;
margin-top: 20px;
flex-wrap: wrap;
}
/* Status & Progress Bar */
.status-panel {
margin-bottom: 20px;
}
.progress-info {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
font-size: 0.95rem;
}
.points-badge {
color: var(--gold-bright);
font-weight: bold;
text-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}
.progress-container {
width: 100%;
height: 12px;
background: rgba(255, 255, 255, 0.08);
border: 1px solid var(--border-gold);
border-radius: 10px;
overflow: hidden;
}
.progress-bar {
height: 100%;
width: 0%;
background: linear-gradient(90deg, var(--gold) 0%, #ffd700 100%);
box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
transition: width 0.4s ease;
}
/* Question Card */
.question-meta {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.badge {
padding: 4px 10px;
border-radius: 12px;
font-size: 0.8rem;
font-weight: bold;
background: rgba(201, 168, 106, 0.15);
border: 1px solid var(--gold);
color: var(--gold-soft);
}
.badge-warning {
background: rgba(243, 156, 18, 0.2);
border-color: var(--warning);
color: #f39c12;
}
.badge-success {
background: rgba(46, 204, 113, 0.2);
border-color: var(--success);
color: #2ecc71;
}
.badge-danger {
background: rgba(231, 76, 60, 0.2);
border-color: var(--danger);
color: #e74c3c;
}
.badge-muted {
background: rgba(255, 255, 255, 0.1);
border-color: rgba(255, 255, 255, 0.2);
color: var(--text-muted);
}
.attempt-badge {
font-size: 0.85rem;
color: var(--text-muted);
}
.question-text {
font-size: 1.4rem;
line-height: 1.5;
text-align: center;
margin: 20px 0 25px;
color: var(--text-main);
}
.answer-form {
display: flex;
flex-direction: column;
align-items: center;
}
.input-answer {
width: 100%;
max-width: 420px;
padding: 14px 18px;
font-size: 1.15rem;
text-align: center;
border-radius: 8px;
border: 2px solid var(--border-gold);
background: rgba(0, 0, 0, 0.3);
color: var(--text-main);
outline: none;
transition: all 0.2s ease;
font-family: inherit;
}
.input-answer:focus {
border-color: var(--gold);
box-shadow: 0 0 12px rgba(201, 168, 106, 0.4);
}
.hint-box {
margin-top: 20px;
padding: 15px;
border-radius: 8px;
background: rgba(201, 168, 106, 0.1);
border-left: 4px solid var(--gold);
font-size: 0.95rem;
color: var(--gold-soft);
text-align: left;
}
.feedback-box {
margin-top: 20px;
font-size: 1.1rem;
text-align: center;
min-height: 30px;
font-weight: bold;
}
.feedback-correct {
color: var(--success);
text-shadow: 0 0 10px rgba(46, 204, 113, 0.4);
}
.feedback-wrong {
color: var(--danger);
}
.feedback-revealed {
color: var(--warning);
font-size: 0.95rem;
}
/* Animations */
.sparkle-effect {
animation: sparkle-glow 0.8s ease forwards;
}
@keyframes sparkle-glow {
0% { box-shadow: 0 0 5px rgba(255, 215, 0, 0.2); }
50% { box-shadow: 0 0 30px rgba(255, 215, 0, 0.8), inset 0 0 20px rgba(255, 215, 0, 0.4); border-color: #ffd700; }
100% { box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); }
}
.shake-effect {
animation: shake 0.4s ease;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
20%, 60% { transform: translateX(-8px); }
40%, 80% { transform: translateX(8px); }
}
/* Finale Page */
.finale-card {
text-align: center;
}
.finale-header {
display: flex;
justify-content: center;
align-items: center;
gap: 15px;
margin-bottom: 20px;
}
.sparkle-icon {
font-size: 2rem;
}
.score-banner {
background: rgba(201, 168, 106, 0.1);
border: 1px dashed var(--gold);
border-radius: 8px;
padding: 15px;
margin-bottom: 25px;
}
.score-highlight {
font-size: 1.25rem;
}
.gold-text {
color: var(--gold-bright);
font-weight: bold;
font-size: 1.5rem;
}
.reward-box {
background: rgba(0, 0, 0, 0.25);
border-radius: 10px;
padding: 25px;
margin-bottom: 25px;
border-left: 4px solid var(--gold);
}
.reward-box h2 {
color: var(--gold-soft);
font-size: 1.4rem;
margin-bottom: 15px;
}
.reward-description {
font-size: 1.1rem;
line-height: 1.6;
margin-bottom: 15px;
color: var(--text-main);
}
.love-note {
font-style: italic;
color: var(--gold);
font-size: 1.15rem;
}
/* Forms & Inputs */
.magic-form {
display: flex;
flex-direction: column;
gap: 18px;
text-align: left;
}
.form-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.form-group label {
font-size: 0.95rem;
font-weight: bold;
color: var(--gold-soft);
}
.input-text, .textarea, select.input-text {
padding: 12px 15px;
border-radius: 6px;
border: 1px solid var(--border-gold);
background: rgba(0, 0, 0, 0.4);
color: var(--text-main);
font-size: 1rem;
font-family: inherit;
outline: none;
width: 100%;
}
.input-text:focus, .textarea:focus {
border-color: var(--gold);
box-shadow: 0 0 10px rgba(201, 168, 106, 0.3);
}
.input-text-sm {
padding: 6px 10px;
border-radius: 4px;
border: 1px solid var(--border-gold);
background: rgba(0,0,0,0.3);
color: var(--text-main);
font-size: 0.9rem;
}
.field-help {
font-size: 0.8rem;
color: var(--text-muted);
}
.info-alert {
background: rgba(41, 128, 185, 0.15);
border-left: 4px solid #3498db;
padding: 15px;
border-radius: 6px;
margin-bottom: 25px;
font-size: 0.95rem;
line-height: 1.5;
}
.alert-danger {
background: rgba(231, 76, 60, 0.2);
border: 1px solid var(--danger);
color: #ff7675;
padding: 12px;
border-radius: 6px;
margin-bottom: 20px;
text-align: center;
}
/* Admin Specific */
.admin-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 25px;
flex-wrap: wrap;
gap: 15px;
}
.admin-top-actions {
display: flex;
gap: 10px;
}
.tabs-nav {
display: flex;
gap: 8px;
border-bottom: 1px solid var(--border-gold);
margin-bottom: 25px;
flex-wrap: wrap;
}
.tab-btn {
background: rgba(255, 255, 255, 0.05);
border: none;
color: var(--text-muted);
padding: 12px 18px;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
cursor: pointer;
font-size: 0.95rem;
font-family: inherit;
font-weight: bold;
display: flex;
align-items: center;
gap: 8px;
transition: all 0.2s ease;
}
.tab-btn:hover {
color: var(--text-main);
background: rgba(255, 255, 255, 0.1);
}
.tab-btn.active {
background: var(--bg-card);
color: var(--gold);
border: 1px solid var(--border-gold);
border-bottom: 1px solid transparent;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.question-admin-card {
margin-bottom: 15px;
}
.q-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
font-size: 0.85rem;
}
.highlight-answer {
color: var(--gold-bright);
font-weight: bold;
background: rgba(255, 215, 0, 0.1);
padding: 2px 6px;
border-radius: 4px;
}
.test-matcher-box {
margin-top: 15px;
padding: 12px;
background: rgba(0, 0, 0, 0.25);
border-radius: 6px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.test-input-group {
display: flex;
gap: 8px;
margin-top: 6px;
}
.test-result-feedback {
margin-top: 8px;
font-size: 0.9rem;
}
.q-actions {
display: flex;
gap: 10px;
margin-top: 15px;
flex-wrap: wrap;
}
.inline-edit-form {
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.empty-state {
text-align: center;
padding: 40px;
color: var(--text-muted);
}
/* Footer */
.footer {
text-align: center;
padding: 20px;
color: var(--text-muted);
font-size: 0.85rem;
border-top: 1px solid rgba(255, 255, 255, 0.05);
margin-top: auto;
}
.hidden {
display: none !important;
}
@media (max-width: 600px) {
.audio-control-bar {
flex-direction: column;
gap: 10px;
}
.glow-title {
font-size: 1.5rem;
}
.card {
padding: 20px 15px;
}
.btn-group {
flex-direction: column;
width: 100%;
}
.btn {
width: 100%;
text-align: center;
}
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

+128
View File
@@ -0,0 +1,128 @@
function showTab(tabId) {
document.querySelectorAll(".tab-content").forEach(el => el.classList.remove("active"));
document.querySelectorAll(".tab-btn").forEach(el => el.classList.remove("active"));
const targetTab = document.getElementById(tabId);
if (targetTab) {
targetTab.classList.add("active");
}
// Mark active button
event.currentTarget.classList.add("active");
}
function toggleEdit(id) {
const editForm = document.getElementById(`edit-form-${id}`);
if (editForm) {
editForm.classList.toggle("hidden");
}
}
async function approveQuestion(id) {
if (!confirm(`Möchtest du Frage #${id} wirklich freischalten und für alle Spieler aktivieren?`)) {
return;
}
try {
const res = await fetch(`/admin/questions/${id}/approve`, {
method: "POST",
headers: { "Content-Type": "application/json" }
});
const data = await res.json();
if (res.ok && data.success) {
alert(data.message);
window.location.reload();
} else {
alert("Fehler: " + (data.error || "Aktion fehlgeschlagen"));
}
} catch (err) {
alert("Netzwerkfehler: " + err.message);
}
}
async function rejectQuestion(id) {
if (!confirm(`Möchtest du Frage #${id} ablehnen?`)) {
return;
}
try {
const res = await fetch(`/admin/questions/${id}/reject`, {
method: "POST",
headers: { "Content-Type": "application/json" }
});
const data = await res.json();
if (res.ok && data.success) {
alert(data.message);
window.location.reload();
} else {
alert("Fehler: " + (data.error || "Aktion fehlgeschlagen"));
}
} catch (err) {
alert("Netzwerkfehler: " + err.message);
}
}
async function deleteQuestion(id) {
if (!confirm(`Soll Frage #${id} wirklich unwiderruflich gelöscht werden?`)) {
return;
}
try {
const res = await fetch(`/admin/questions/${id}/delete`, {
method: "POST",
headers: { "Content-Type": "application/json" }
});
const data = await res.json();
if (res.ok && data.success) {
const card = document.getElementById(`q-card-${id}`);
if (card) card.remove();
} else {
alert("Fehler beim Löschen: " + (data.error || ""));
}
} catch (err) {
alert("Netzwerkfehler: " + err.message);
}
}
async function testMatcher(id, canonical) {
const input = document.getElementById(`test-input-${id}`);
const resultBox = document.getElementById(`test-result-${id}`);
const testVal = input.value.trim();
if (!testVal) {
resultBox.innerHTML = '<span style="color: #f39c12;">Bitte gib einen Testwert ein.</span>';
return;
}
try {
const formData = new FormData();
formData.append("test_input", testVal);
formData.append("canonical", canonical);
const res = await fetch("/admin/questions/test-match", {
method: "POST",
body: formData
});
const data = await res.json();
if (data.matched) {
resultBox.innerHTML = `
<span style="color: #2ecc71; font-weight: bold;">
✅ Treffer! (Distanz: ${data.levenshtein_distance}, Bereinigt: "${data.input_clean}" ↔ "${data.target_clean}")
</span>
`;
} else {
resultBox.innerHTML = `
<span style="color: #e74c3c; font-weight: bold;">
❌ Kein Treffer (Distanz: ${data.levenshtein_distance}, Bereinigt: "${data.input_clean}" ↔ "${data.target_clean}")
</span>
`;
}
} catch (err) {
resultBox.innerHTML = '<span style="color: #e74c3c;">Fehler bei der Prüfung.</span>';
}
}
+249
View File
@@ -0,0 +1,249 @@
let currentSessionId = null;
let currentQuestionNumber = 1;
let totalQuestions = 15;
let currentScore = 0;
let attemptsUsed = 0;
const maxAttempts = 3;
// Web Audio API Sound Generator for magic chimes and buzzers
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
function playSound(type) {
if (audioCtx.state === 'suspended') {
audioCtx.resume();
}
if (type === 'magic') {
// Magical bright arpeggio chime
const notes = [523.25, 659.25, 783.99, 1046.50]; // C5, E5, G5, C6
notes.forEach((freq, index) => {
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'sine';
osc.frequency.value = freq;
gain.gain.setValueAtTime(0.15, audioCtx.currentTime + index * 0.08);
gain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + index * 0.08 + 0.35);
osc.connect(gain);
gain.connect(audioCtx.destination);
osc.start(audioCtx.currentTime + index * 0.08);
osc.stop(audioCtx.currentTime + index * 0.08 + 0.35);
});
} else if (type === 'wrong') {
// Soft error buzz
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'sawtooth';
osc.frequency.setValueAtTime(150, audioCtx.currentTime);
osc.frequency.exponentialRampToValueAtTime(80, audioCtx.currentTime + 0.25);
gain.gain.setValueAtTime(0.1, audioCtx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + 0.25);
osc.connect(gain);
gain.connect(audioCtx.destination);
osc.start();
osc.stop(audioCtx.currentTime + 0.25);
}
}
async function startGame() {
const envelope = document.getElementById("envelope");
const startBtn = document.getElementById("startBtn");
startBtn.disabled = true;
startBtn.innerText = "✨ Zauber wird gewirkt...";
envelope.classList.add("envelope-opened");
// Start background music if enabled or first click
const bgm = document.getElementById("bgm");
if (bgm && bgm.paused) {
bgm.play().then(() => {
const icon = document.getElementById("audioIcon");
const text = document.getElementById("audioText");
if (icon && text) {
icon.innerText = "🔊";
text.innerText = "Musik: An";
}
localStorage.setItem("bgm_enabled", "true");
}).catch(() => {});
}
try {
const res = await fetch("/api/game/start", {
method: "POST",
headers: { "Content-Type": "application/json" }
});
if (!res.ok) {
throw new Error("Konnte Spiel nicht starten.");
}
const data = await res.json();
currentSessionId = data.session_id;
currentQuestionNumber = data.question_number;
totalQuestions = data.total_questions;
currentScore = data.score;
attemptsUsed = data.attempts_used;
setTimeout(() => {
document.getElementById("introCard").classList.add("hidden");
document.getElementById("gameCard").classList.remove("hidden");
renderQuestion(data);
}, 1100);
} catch (err) {
alert("Fehler beim Starten des Quiz: " + err.message);
startBtn.disabled = false;
startBtn.innerText = "📜 Siegel brechen & Brief öffnen";
envelope.classList.remove("envelope-opened");
}
}
function renderQuestion(qData) {
document.getElementById("questionCounter").innerText = `Frage ${qData.question_number} von ${totalQuestions}`;
document.getElementById("pointsCounter").innerText = `🏆 Hauspunkte: ${currentScore}`;
document.getElementById("badgeCategory").innerText = `⚡ ${qData.category.replace("_", " ").toUpperCase()}`;
document.getElementById("attemptBadge").innerText = `Versuch ${attemptsUsed + 1} von ${maxAttempts}`;
document.getElementById("frageText").innerText = qData.question;
const input = document.getElementById("answerInput");
input.value = "";
input.disabled = false;
input.focus();
document.getElementById("checkBtn").disabled = false;
document.getElementById("hintBtn").disabled = false;
document.getElementById("hintBox").classList.add("hidden");
document.getElementById("feedbackBox").innerHTML = "";
updateProgress();
}
function updateProgress() {
const percent = ((currentQuestionNumber - 1) / totalQuestions) * 100;
document.getElementById("progressBar").style.width = percent + "%";
}
async function checkAnswer() {
const input = document.getElementById("answerInput");
const answer = input.value.trim();
if (!answer) {
input.focus();
return;
}
const checkBtn = document.getElementById("checkBtn");
checkBtn.disabled = true;
try {
const res = await fetch("/api/game/check", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
session_id: currentSessionId,
answer: answer
})
});
if (!res.ok) {
throw new Error("Fehler bei der Antwortprüfung.");
}
const result = await res.json();
currentScore = result.score;
document.getElementById("pointsCounter").innerText = `🏆 Hauspunkte: ${currentScore}`;
const frageBox = document.getElementById("frageBox");
const feedbackBox = document.getElementById("feedbackBox");
if (result.correct) {
// Success!
playSound('magic');
frageBox.classList.add("sparkle-effect");
feedbackBox.innerHTML = `<span class="feedback-correct">✨ Richtig! 1 Hauspunkt für dein Haus! ✨</span>`;
input.disabled = true;
setTimeout(() => {
frageBox.classList.remove("sparkle-effect");
if (result.is_finished) {
finishGame();
} else if (result.next_question) {
currentQuestionNumber = result.next_question.question_number;
attemptsUsed = 0;
renderQuestion(result.next_question);
}
}, 1200);
} else {
// Incorrect
playSound('wrong');
frageBox.classList.add("shake-effect");
setTimeout(() => frageBox.classList.remove("shake-effect"), 500);
attemptsUsed = result.attempts_used;
document.getElementById("attemptBadge").innerText = `Versuch ${Math.min(attemptsUsed + 1, maxAttempts)} von ${maxAttempts}`;
if (result.attempts_left === 0) {
// Exhausted all 3 attempts
feedbackBox.innerHTML = `
<div class="feedback-wrong">Leider nicht richtig (3 Fehlversuche).</div>
<div class="feedback-revealed">Richtige Lösung: <strong>${result.revealed_answer}</strong></div>
`;
input.disabled = true;
setTimeout(() => {
if (result.is_finished) {
finishGame();
} else if (result.next_question) {
currentQuestionNumber = result.next_question.question_number;
attemptsUsed = 0;
renderQuestion(result.next_question);
}
}, 2200);
} else {
// Still attempts remaining
feedbackBox.innerHTML = `<span class="feedback-wrong">Leider falsch! Noch ${result.attempts_left} Versuch(e).</span>`;
checkBtn.disabled = false;
input.select();
}
}
} catch (err) {
alert("Netzwerkfehler: " + err.message);
checkBtn.disabled = false;
}
}
async function requestHint() {
if (!currentSessionId) return;
const hintBox = document.getElementById("hintBox");
const hintText = document.getElementById("hintText");
try {
const res = await fetch(`/api/game/hint?session_id=${encodeURIComponent(currentSessionId)}`);
const data = await res.json();
hintText.innerText = data.hint || "Kein Tipp vorhanden.";
hintBox.classList.remove("hidden");
} catch (err) {
hintText.innerText = "Tipp konnte nicht geladen werden.";
hintBox.classList.remove("hidden");
}
}
function finishGame() {
// 100% progress
document.getElementById("progressBar").style.width = "100%";
window.location.href = `/finale?score=${currentScore}&total=${totalQuestions}`;
}
// Enter key to submit
document.addEventListener("DOMContentLoaded", () => {
const input = document.getElementById("answerInput");
if (input) {
input.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
e.preventDefault();
checkAnswer();
}
});
}
});
+61
View File
@@ -0,0 +1,61 @@
async function submitSuggestion(event) {
event.preventDefault();
const name = document.getElementById("name").value.trim();
const frage = document.getElementById("frage").value.trim();
const antwort = document.getElementById("antwort").value.trim();
const tipp = document.getElementById("tipp").value.trim();
const submitBtn = document.getElementById("submitBtn");
const resultBox = document.getElementById("resultMessage");
if (!frage || !antwort) {
alert("Bitte gib mindestens die Frage und die richtige Antwort ein.");
return;
}
submitBtn.disabled = true;
submitBtn.innerText = "✨ Vorschlag wird übertragen...";
try {
const res = await fetch("/api/suggestions", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: name || "Gast",
frage: frage,
antwort: antwort,
tipp: tipp || null
})
});
const data = await res.json();
if (res.ok && data.success) {
resultBox.innerHTML = `
<div style="background: rgba(46, 204, 113, 0.2); border: 1px solid #2ecc71; color: #55efc4; padding: 15px; border-radius: 8px;">
<h3>✨ Vorschlag erfolgreich übermittelt! ✨</h3>
<p>${data.message}</p>
</div>
`;
resultBox.classList.remove("hidden");
document.getElementById("suggestionForm").reset();
} else {
resultBox.innerHTML = `
<div class="alert alert-danger">
${data.detail || "Fehler beim Einreichen deines Vorschlags."}
</div>
`;
resultBox.classList.remove("hidden");
}
} catch (err) {
resultBox.innerHTML = `
<div class="alert alert-danger">
Netzwerkfehler: ${err.message}
</div>
`;
resultBox.classList.remove("hidden");
} finally {
submitBtn.disabled = false;
submitBtn.innerText = "📜 Vorschlag an das Ministerium senden";
}
}