handling remaining questions amount
This commit is contained in:
parent
a68bc1e08e
commit
cc4c335185
|
|
@ -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(<GameAnswerExplanation questionId={answerKey} />);
|
||||
|
|
@ -117,6 +119,7 @@ export function GameContextProvider({ children }) {
|
|||
initAnswers,
|
||||
isSoundOn,
|
||||
setIsSoundOn,
|
||||
remainingQuestionsAmount,
|
||||
buildGameStatsObject,
|
||||
answerQuestion,
|
||||
hasCheckedTutorial,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user