initial page
This commit is contained in:
202
public/app.js
Normal file
202
public/app.js
Normal file
@@ -0,0 +1,202 @@
|
||||
// API Base URL
|
||||
const API_BASE = '';
|
||||
|
||||
// Globale Variablen
|
||||
let totalPoints = 0;
|
||||
let tasks = [];
|
||||
|
||||
// Initialisiere die App
|
||||
async function init() {
|
||||
await loadTasks();
|
||||
calculateTotalPoints();
|
||||
renderTasks();
|
||||
updateProgress();
|
||||
}
|
||||
|
||||
// Berechne Gesamtpunktzahl aus abgeschlossenen Aufgaben
|
||||
function calculateTotalPoints() {
|
||||
totalPoints = tasks
|
||||
.filter(task => task.isCorrect === true)
|
||||
.reduce((sum, task) => sum + (task.points || 0), 0);
|
||||
updatePointsDisplay();
|
||||
}
|
||||
|
||||
// Lade Aufgaben vom Server
|
||||
async function loadTasks() {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/api/tasks`);
|
||||
const data = await response.json();
|
||||
tasks = data.tasks || [];
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden der Aufgaben:', error);
|
||||
tasks = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Rendere Aufgaben
|
||||
function renderTasks() {
|
||||
const container = document.getElementById('taskContainer');
|
||||
container.innerHTML = '';
|
||||
|
||||
tasks.forEach(task => {
|
||||
const taskCard = document.createElement('div');
|
||||
taskCard.className = 'task-card';
|
||||
taskCard.id = `task-${task.id}`;
|
||||
|
||||
const isCompleted = task.isCorrect === true;
|
||||
const hasAnswer = task.userAnswer !== undefined;
|
||||
|
||||
taskCard.innerHTML = `
|
||||
<div class="task-header">
|
||||
<div class="task-title">Aufgabe</div>
|
||||
<div class="task-points">⭐ ${task.points} Punkte</div>
|
||||
</div>
|
||||
<div class="task-question">${task.question}</div>
|
||||
<div class="task-input-group">
|
||||
<input
|
||||
type="number"
|
||||
class="task-input"
|
||||
id="input-${task.id}"
|
||||
placeholder="?"
|
||||
value="${hasAnswer ? task.userAnswer : ''}"
|
||||
${isCompleted ? 'disabled' : ''}
|
||||
>
|
||||
<button
|
||||
class="task-button"
|
||||
onclick="checkAnswer('${task.id}')"
|
||||
${isCompleted ? 'disabled' : ''}
|
||||
>
|
||||
Prüfen
|
||||
</button>
|
||||
</div>
|
||||
<div class="task-status" id="status-${task.id}">
|
||||
${isCompleted ? '✅ Richtig beantwortet!' : hasAnswer && !isCompleted ? '❌ Falsch - versuche es nochmal!' : ''}
|
||||
</div>
|
||||
`;
|
||||
|
||||
if (isCompleted) {
|
||||
const statusEl = taskCard.querySelector('.task-status');
|
||||
statusEl.className = 'task-status success';
|
||||
} else if (hasAnswer && !isCompleted) {
|
||||
const statusEl = taskCard.querySelector('.task-status');
|
||||
statusEl.className = 'task-status error';
|
||||
}
|
||||
|
||||
container.appendChild(taskCard);
|
||||
});
|
||||
}
|
||||
|
||||
// Prüfe Antwort
|
||||
async function checkAnswer(taskId) {
|
||||
const task = tasks.find(t => t.id === taskId);
|
||||
if (!task) return;
|
||||
|
||||
const input = document.getElementById(`input-${taskId}`);
|
||||
const status = document.getElementById(`status-${taskId}`);
|
||||
const button = input.nextElementSibling;
|
||||
|
||||
const userAnswer = parseInt(input.value);
|
||||
|
||||
if (isNaN(userAnswer)) {
|
||||
status.textContent = 'Bitte gib eine Zahl ein!';
|
||||
status.className = 'task-status error';
|
||||
return;
|
||||
}
|
||||
|
||||
// Prüfe ob Aufgabe bereits korrekt beantwortet wurde
|
||||
if (task.isCorrect === true) {
|
||||
status.textContent = '✅ Diese Aufgabe wurde bereits richtig beantwortet!';
|
||||
status.className = 'task-status completed';
|
||||
return;
|
||||
}
|
||||
|
||||
// Sende Antwort an Backend zur Prüfung
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/api/check-answer`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ taskId, answer: userAnswer })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Lade Tasks neu, um die gespeicherte Antwort zu erhalten
|
||||
await loadTasks();
|
||||
calculateTotalPoints();
|
||||
|
||||
if (data.correct) {
|
||||
status.textContent = '🎉 Richtig! Super gemacht!';
|
||||
status.className = 'task-status success';
|
||||
|
||||
// Deaktiviere Input und Button
|
||||
input.disabled = true;
|
||||
button.disabled = true;
|
||||
|
||||
// Zeige Erfolgsnachricht
|
||||
showMessage(`🎉 ${data.points} Quest-Punkte verdient!`, 'success');
|
||||
} else {
|
||||
status.textContent = '❌ Nicht ganz richtig. Versuch es nochmal!';
|
||||
status.className = 'task-status error';
|
||||
input.focus();
|
||||
}
|
||||
|
||||
// Rendere Tasks neu, um den aktuellen Status anzuzeigen
|
||||
renderTasks();
|
||||
updateProgress();
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Prüfen der Antwort:', error);
|
||||
status.textContent = 'Fehler beim Prüfen. Bitte versuche es erneut.';
|
||||
status.className = 'task-status error';
|
||||
}
|
||||
}
|
||||
|
||||
// Aktualisiere Punkte-Anzeige
|
||||
function updatePointsDisplay() {
|
||||
document.getElementById('totalPoints').textContent = totalPoints;
|
||||
}
|
||||
|
||||
// Berechne maximale mögliche Punkte (Summe aller Tasks)
|
||||
function calculateMaxPoints() {
|
||||
return tasks.reduce((sum, task) => sum + (task.points || 0), 0);
|
||||
}
|
||||
|
||||
// Aktualisiere Progress-Balken
|
||||
function updateProgress() {
|
||||
const maxPoints = calculateMaxPoints();
|
||||
const percentage = maxPoints > 0 ? Math.min((totalPoints / maxPoints) * 100, 100) : 0;
|
||||
|
||||
const progressBar = document.getElementById('progressBar');
|
||||
const progressText = document.getElementById('progressText');
|
||||
|
||||
progressBar.style.width = `${percentage}%`;
|
||||
progressText.textContent = `${totalPoints} / ${maxPoints}`;
|
||||
}
|
||||
|
||||
// Zeige Nachricht
|
||||
function showMessage(text, type) {
|
||||
const message = document.getElementById('message');
|
||||
message.textContent = text;
|
||||
message.className = `message ${type} show`;
|
||||
|
||||
setTimeout(() => {
|
||||
message.classList.remove('show');
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// Enter-Taste für Input-Felder
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
init();
|
||||
|
||||
// Event Listener für Enter-Taste
|
||||
document.addEventListener('keypress', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
const input = document.activeElement;
|
||||
if (input && input.classList.contains('task-input')) {
|
||||
const taskId = input.id.replace('input-', '');
|
||||
checkAnswer(taskId);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
39
public/index.html
Normal file
39
public/index.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>MathQuest - Mathe lernen mit Quest-Punkten!</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>🌟 MathQuest 🌟</h1>
|
||||
<div class="points-display">
|
||||
<div class="points-label">Quest-Punkte</div>
|
||||
<div class="points-value" id="totalPoints">0</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="progress-section">
|
||||
<div class="progress-label">Fortschritt</div>
|
||||
<div class="progress-bar-container">
|
||||
<div class="progress-bar" id="progressBar"></div>
|
||||
</div>
|
||||
<div class="progress-text" id="progressText">0 / 100</div>
|
||||
</div>
|
||||
|
||||
<div class="task-section">
|
||||
<h2>Mathe-Aufgaben</h2>
|
||||
<div id="taskContainer" class="task-container">
|
||||
<!-- Aufgaben werden hier dynamisch eingefügt -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="message" id="message"></div>
|
||||
</div>
|
||||
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
274
public/style.css
Normal file
274
public/style.css
Normal file
@@ -0,0 +1,274 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', cursive, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5em;
|
||||
color: #667eea;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.points-display {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
padding: 20px;
|
||||
border-radius: 15px;
|
||||
color: white;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.points-label {
|
||||
font-size: 1.2em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.points-value {
|
||||
font-size: 3em;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.progress-section {
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.progress-label {
|
||||
font-size: 1.3em;
|
||||
color: #667eea;
|
||||
margin-bottom: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.progress-bar-container {
|
||||
width: 100%;
|
||||
height: 30px;
|
||||
background: #e0e0e0;
|
||||
border-radius: 15px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 10px;
|
||||
box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
|
||||
width: 0%;
|
||||
transition: width 0.5s ease;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
font-size: 1.1em;
|
||||
color: #666;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.task-section {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.task-section h2 {
|
||||
color: #667eea;
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
font-size: 1.8em;
|
||||
}
|
||||
|
||||
.task-container {
|
||||
display: grid;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.task-card {
|
||||
background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
|
||||
padding: 25px;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.task-card:hover {
|
||||
transform: translateY(-3px);
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.task-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.task-title {
|
||||
font-size: 1.3em;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.task-points {
|
||||
background: #ffd700;
|
||||
color: #333;
|
||||
padding: 5px 15px;
|
||||
border-radius: 20px;
|
||||
font-weight: bold;
|
||||
font-size: 1.1em;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.task-question {
|
||||
font-size: 1.5em;
|
||||
text-align: center;
|
||||
margin: 20px 0;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.task-input-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.task-input {
|
||||
font-size: 1.5em;
|
||||
padding: 10px 15px;
|
||||
border: 3px solid #667eea;
|
||||
border-radius: 10px;
|
||||
width: 120px;
|
||||
text-align: center;
|
||||
font-family: 'Comic Sans MS', cursive;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.task-input:focus {
|
||||
outline: none;
|
||||
border-color: #764ba2;
|
||||
box-shadow: 0 0 10px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.task-button {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 25px;
|
||||
font-size: 1.2em;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
font-family: 'Comic Sans MS', cursive;
|
||||
font-weight: bold;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.task-button:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.task-button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.task-button:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.task-status {
|
||||
text-align: center;
|
||||
font-size: 1.1em;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
min-height: 25px;
|
||||
}
|
||||
|
||||
.task-status.success {
|
||||
color: #4caf50;
|
||||
}
|
||||
|
||||
.task-status.error {
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
.task-status.completed {
|
||||
color: #ff9800;
|
||||
}
|
||||
|
||||
.message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
padding: 15px 25px;
|
||||
border-radius: 10px;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
|
||||
transform: translateX(400px);
|
||||
transition: transform 0.3s ease;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.message.show {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.message.success {
|
||||
background: #4caf50;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.message.error {
|
||||
background: #f44336;
|
||||
color: white;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
.points-value {
|
||||
font-size: 2.5em;
|
||||
}
|
||||
|
||||
.task-input-group {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.task-button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user