From cc4c335185766fb8d9cc6239311b1b5cbc7945c9 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Thu, 16 May 2024 17:06:05 +0200 Subject: [PATCH] handling remaining questions amount --- src/context/GameContext.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/context/GameContext.js b/src/context/GameContext.js index 899fe97..7c536a8 100644 --- a/src/context/GameContext.js +++ b/src/context/GameContext.js @@ -20,6 +20,7 @@ export function GameContextProvider({ children }) { const [answers, setAnswers] = useState(null); const [score, setScore] = useState(null); const [gameTime, setGameTime] = useState(0); + const [remainingQuestionsAmount, setRemainingQuestionsAmount] = useState(null); // ##### INTERFACE ##### const [hasCheckedTutorial, setHasCheckedTutorial] = useState(false); @@ -34,6 +35,7 @@ export function GameContextProvider({ children }) { useEffect(() => { if (!contextGameDatas) return; initAnswers(); + setRemainingQuestionsAmount(contextGameDatas.gameObjects.length); }, [contextGameDatas]); function initAnswers() { @@ -53,7 +55,7 @@ export function GameContextProvider({ children }) { newAnswers[answerKey].userAnswer = answer; newAnswers[answerKey].userAnsweredCorrectly = answer === newAnswers[answerKey].correctAnswer; setAnswers(newAnswers); - + setRemainingQuestionsAmount(remainingQuestionsAmount - 1); const newScore = calculateScore(answers); setScore(newScore); setCurrentGameModal(); @@ -117,6 +119,7 @@ export function GameContextProvider({ children }) { initAnswers, isSoundOn, setIsSoundOn, + remainingQuestionsAmount, buildGameStatsObject, answerQuestion, hasCheckedTutorial,