-
@@ -480,6 +505,7 @@
const timerProgress = document.getElementById('timerProgress');
const timerText = document.getElementById('timerText');
const questionText = document.getElementById('questionText');
+ const questionWrapper = document.getElementById('questionWrapper');
const optionsContainer = document.getElementById('optionsContainer');
const feedback = document.getElementById('feedback');
const nextBtn = document.getElementById('nextBtn');
@@ -490,10 +516,8 @@
const qrImage = document.getElementById('qrImage');
const qrLink = document.getElementById('qrLink');
- // Опции кнопок
const optionBtns = document.querySelectorAll('.option-btn');
- // Начать новую игру
async function startNewGame() {
try {
const response = await fetch('/api/new_game', {
@@ -513,9 +537,10 @@
questionArea.classList.remove('hidden');
resultArea.classList.add('hidden');
questionsReview.classList.add('hidden');
- qrContainer.classList.remove('show');
isAnswered = false;
+ removeQuestionHighlight();
+
startTimer(10);
} catch (error) {
console.error('Ошибка:', error);
@@ -523,7 +548,20 @@
}
}
- // Отображение вопроса
+ function highlightQuestion(isCorrect) {
+ removeQuestionHighlight();
+ if (isCorrect) {
+ questionWrapper.classList.add('correct-highlight');
+ } else {
+ questionWrapper.classList.add('wrong-highlight');
+ }
+ }
+
+ function removeQuestionHighlight() {
+ questionWrapper.classList.remove('correct-highlight');
+ questionWrapper.classList.remove('wrong-highlight');
+ }
+
function displayQuestion(question, qNumber) {
if (!question) return;
@@ -531,7 +569,6 @@
questionCounter.textContent = `Вопрос ${qNumber}/${totalQuestions}`;
questionText.textContent = question.text;
- // Обновляем варианты ответов
question.options.forEach((option, index) => {
if (optionBtns[index]) {
optionBtns[index].textContent = `${String.fromCharCode(65+index)}. ${option}`;
@@ -540,13 +577,12 @@
}
});
- // Скрываем фидбек и кнопку далее
feedback.classList.add('hidden');
nextBtn.classList.add('hidden');
isAnswered = false;
+ removeQuestionHighlight();
}
- // Таймер
function startTimer(seconds) {
if (timerInterval) clearInterval(timerInterval);
@@ -580,17 +616,16 @@
}
}
- // Обработка timeout
async function handleTimeout() {
if (isAnswered) return;
isAnswered = true;
clearInterval(timerInterval);
- // Отключаем кнопки
+ highlightQuestion(false);
+
optionBtns.forEach(btn => btn.disabled = true);
- // Отправляем пустой ответ (время вышло)
try {
const response = await fetch('/api/check_answer', {
method: 'POST',
@@ -618,30 +653,37 @@
}
}
- // Обработка ответа пользователя
async function handleAnswer(answerIndex) {
if (isAnswered) return;
isAnswered = true;
clearInterval(timerInterval);
- // Визуальная обратная связь
const selectedBtn = optionBtns[answerIndex];
+
+ // ВАЖНО: проверяем правильность ответа
+ // currentQuestion.correct приходит от сервера с индексом правильного ответа
const isCorrect = (answerIndex === currentQuestion.correct);
+ console.log('Answer index:', answerIndex);
+ console.log('Correct index:', currentQuestion.correct);
+ console.log('Is correct:', isCorrect);
+
+ // Подсвечиваем вопрос
+ highlightQuestion(isCorrect);
+
if (isCorrect) {
selectedBtn.classList.add('correct');
+ currentScore++;
+ updateScoreDisplay();
} else {
selectedBtn.classList.add('wrong');
- // Показываем правильный ответ
const correctBtn = optionBtns[currentQuestion.correct];
if (correctBtn) correctBtn.classList.add('correct');
}
- // Отключаем все кнопки
optionBtns.forEach(btn => btn.disabled = true);
- // Отправляем ответ на сервер
try {
const response = await fetch('/api/check_answer', {
method: 'POST',
@@ -665,7 +707,6 @@
}
}
- // Показать фидбек после ответа
function showFeedback(result) {
const feedbackTitle = document.getElementById('feedbackTitle');
const feedbackText = document.getElementById('feedbackText');
@@ -673,8 +714,6 @@
if (result.is_correct) {
feedbackTitle.textContent = '✅ Правильно!';
feedbackTitle.style.color = '#28a745';
- currentScore = result.score;
- updateScoreDisplay();
feedbackText.textContent = result.explanation || 'Отличный результат!';
} else {
feedbackTitle.textContent = '❌ Неправильно!';
@@ -685,7 +724,6 @@
feedback.classList.remove('hidden');
}
- // Загрузить следующий вопрос
function loadNextQuestion(data) {
if (data.next_question) {
displayQuestion(data.next_question, data.question_number);
@@ -693,7 +731,6 @@
}
}
- // Показать все вопросы с ответами
function displayAllQuestions(questionsSummary) {
questionsReview.innerHTML = '
📋 Детальный разбор всех вопросов
';
questionsReview.classList.remove('hidden');
@@ -728,30 +765,26 @@
});
}
- // Показать QR-код
- async function showQRCode(resultId) {
+ async function displayQRCode(resultId) {
try {
const response = await fetch(`/api/qrcode/${resultId}`);
if (response.ok) {
const blob = await response.blob();
const url = URL.createObjectURL(blob);
qrImage.src = url;
-
- // Показываем ссылку
+
+ // Ссылка на изображение с результатами
const fullUrl = window.location.origin + `/api/result/${resultId}`;
- qrLink.innerHTML = `
${fullUrl}`;
-
- qrContainer.classList.add('show');
+ qrLink.innerHTML = `📎 Ссылка на результат:
${fullUrl}`;
} else {
- alert('Не удалось сгенерировать QR-код');
+ qrContainer.innerHTML = '
❌ Не удалось сгенерировать QR-код
';
}
} catch (error) {
console.error('Ошибка:', error);
- alert('Ошибка при генерации QR-кода');
+ qrContainer.innerHTML = '
❌ Ошибка при генерации QR-кода
';
}
}
- // Показать результат
function showResult(result) {
clearInterval(timerInterval);
questionArea.classList.add('hidden');
@@ -766,18 +799,17 @@
resultMessage.textContent = result.message;
currentResultId = result.result_id;
- // Показываем разбор вопросов (после кнопок)
+ displayQRCode(currentResultId);
+
if (result.questions_summary) {
displayAllQuestions(result.questions_summary);
}
}
- // Обновить отображение счёта
function updateScoreDisplay() {
scoreDisplay.textContent = `Счёт: ${currentScore}`;
}
- // Обработчики событий
optionBtns.forEach(btn => {
btn.addEventListener('click', () => {
const index = parseInt(btn.dataset.index);
@@ -789,19 +821,6 @@
startNewGame();
});
- document.getElementById('showQrBtn').addEventListener('click', () => {
- if (currentResultId) {
- showQRCode(currentResultId);
- } else {
- alert('Результаты ещё не готовы');
- }
- });
-
- document.getElementById('hideQrBtn').addEventListener('click', () => {
- qrContainer.classList.remove('show');
- });
-
- // Запуск игры
startNewGame();