From 49948ca90dc656ba339aaf26204ee72bdcca6d7d Mon Sep 17 00:00:00 2001 From: scayac Date: Wed, 28 Jan 2026 18:08:25 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20boitier=20et=20index.htm?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/index.html | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/html/index.html b/html/index.html index 8bad50b..e127867 100644 --- a/html/index.html +++ b/html/index.html @@ -782,6 +782,12 @@ } showResultsBtn.disabled = !allAnswered || connectedModules.size === 0; + + // Afficher automatiquement les résultats si tous les modules ont répondu + if (allAnswered && connectedModules.size > 0 && !resultsShown) { + console.log('✅ Tous les modules ont répondu - Calcul automatique des scores'); + showResults(); + } } function showResults() { @@ -789,7 +795,10 @@ resultsShown = true; const question = questions[currentQuestionIndex]; - const correctAnswerIndex = question.correctAnswer; + // Utiliser la position mélangée de la bonne réponse + const correctAnswerIndex = question.shuffledCorrectAnswer !== undefined + ? question.shuffledCorrectAnswer + : question.correctAnswer; const correctLetter = ['A', 'B', 'C', 'D'][correctAnswerIndex]; const scoringConfig = getScoringConfig(); @@ -1023,6 +1032,16 @@ showQuestion(); } + // Fonction pour mélanger un tableau (algorithme Fisher-Yates) + function shuffleArray(array) { + const shuffled = [...array]; + for (let i = shuffled.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; + } + return shuffled; + } + function showQuestion() { if (currentQuestionIndex >= questions.length) { showFinalScore(); @@ -1032,17 +1051,27 @@ resultsShown = false; const question = questions[currentQuestionIndex]; + // Mélanger les réponses et mémoriser la nouvelle position de la bonne réponse + const originalAnswers = question.answers; + const answerIndices = [0, 1, 2, 3]; // Indices originaux + const shuffledIndices = shuffleArray(answerIndices); + const shuffledAnswers = shuffledIndices.map(i => originalAnswers[i]); + + // Stocker la nouvelle position de la bonne réponse + const newCorrectAnswerIndex = shuffledIndices.indexOf(question.correctAnswer); + question.shuffledCorrectAnswer = newCorrectAnswerIndex; + // Afficher la question document.querySelector('.question-number').textContent = `Question ${currentQuestionIndex + 1}/${questions.length}`; document.querySelector('.question-text').innerHTML = formatText(question.question); - // Afficher les réponses + // Afficher les réponses mélangées const answersContainer = document.getElementById('answersContainer'); answersContainer.innerHTML = ''; const letters = ['A', 'B', 'C', 'D']; - question.answers.forEach((answer, index) => { + shuffledAnswers.forEach((answer, index) => { const answerDiv = document.createElement('div'); answerDiv.className = 'answer'; @@ -1085,6 +1114,12 @@ } function showNextQuestion() { + // Calculer les scores avant de passer à la question suivante + // (même si tous les modules n'ont pas répondu) + if (!resultsShown && currentQuestionIndex < questions.length) { + showResults(); + } + if (currentQuestionIndex < questions.length - 1) { currentQuestionIndex++; showQuestion();