Added quiz starter templates

This commit is contained in:
2025-11-17 23:07:52 +03:00
parent 8abac1840f
commit 61f2a71410
47 changed files with 355 additions and 1924 deletions

104
static/script.js Normal file
View File

@@ -0,0 +1,104 @@
// TODO: Inna - Implement frontend game functionality
let gameState = {
currentQuestion: null,
optionsDisabled: false
};
function loadQuestion() {
fetch('/get_question')
.then(response => response.json())
.then(data => {
if (data.error) {
console.error(data.error);
return;
}
if (data.game_over) {
endGame(data.final_score);
return;
}
gameState.currentQuestion = data;
displayQuestion(data);
})
.catch(error => console.error('Error:', error));
}
function displayQuestion(questionData) {
document.getElementById('question-num').textContent = questionData.question_number;
document.getElementById('question-text').textContent = questionData.question;
const optionsContainer = document.getElementById('options-container');
optionsContainer.innerHTML = '';
const optionLetters = ['A', 'B', 'C', 'D'];
questionData.options.forEach((option, index) => {
const optionElement = document.createElement('div');
optionElement.className = 'option';
optionElement.textContent = `${optionLetters[index]}. ${option}`;
optionElement.onclick = () => selectAnswer(option);
optionsContainer.appendChild(optionElement);
});
document.getElementById('feedback').style.display = 'none';
gameState.optionsDisabled = false;
}
function selectAnswer(selectedAnswer) {
if (gameState.optionsDisabled) return;
gameState.optionsDisabled = true;
fetch('/answer', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ answer: selectedAnswer })
})
.then(response => response.json())
.then(data => {
const feedback = document.getElementById('feedback');
feedback.style.display = 'block';
if (data.correct) {
feedback.textContent = 'Correct! 🎉';
feedback.className = 'feedback correct';
setTimeout(() => {
if (data.next_question) loadQuestion();
else endGame(data.final_score, true);
}, 1500);
} else {
feedback.textContent = `Incorrect! Correct answer: ${data.correct_answer}`;
feedback.className = 'feedback incorrect';
setTimeout(() => endGame(data.final_score), 2000);
}
})
.catch(error => console.error('Error:', error));
}
function useLifeline(lifelineName) {
fetch(`/lifeline/${lifelineName}`)
.then(response => response.json())
.then(data => {
if (data.error) {
alert(data.error);
return;
}
document.getElementById('lifeline-result').textContent =
data.hint || data.friend_says || 'Lifeline used!';
})
.catch(error => console.error('Error:', error));
}
function endGame(finalScore, isWin = false) {
document.getElementById('final-prize').textContent = finalScore;
document.getElementById('game-over-screen').style.display = 'block';
document.querySelector('.game-area').style.display = 'none';
}
function restartGame() {
window.location.href = '/start';
}
document.addEventListener('DOMContentLoaded', function() {
if (window.location.pathname === '/start') {
loadQuestion();
}
});

105
static/style.css Normal file
View File

@@ -0,0 +1,105 @@
/* TODO: Artyom - Enhance this CSS with Russian-themed design */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
body {
background: #1a2a6c;
color: white;
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 20px;
}
header {
text-align: center;
margin-bottom: 20px;
padding: 15px;
background: #b21f1f;
border-radius: 8px;
}
h1 {
font-size: 2.5rem;
margin-bottom: 10px;
}
.question-container {
background: rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
}
.question {
font-size: 1.3rem;
margin-bottom: 20px;
text-align: center;
}
.options-container {
display: grid;
gap: 10px;
}
.option {
background: #fdbb2d;
color: #1a2a6c;
padding: 15px;
border-radius: 5px;
cursor: pointer;
text-align: center;
font-weight: bold;
}
.option:hover {
background: #e6a923;
}
.lifelines {
background: rgba(255, 255, 255, 0.1);
padding: 15px;
border-radius: 8px;
}
.lifeline-buttons {
display: flex;
gap: 10px;
justify-content: center;
}
.lifeline-btn {
background: #1a2a6c;
color: white;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
}
.start-btn {
background: #fdbb2d;
color: #1a2a6c;
border: none;
padding: 15px 30px;
border-radius: 25px;
font-size: 1.2rem;
cursor: pointer;
display: block;
margin: 20px auto;
}
.game-over-screen {
text-align: center;
padding: 30px;
}