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 [answers, setAnswers] = useState(null);
|
||||||
const [score, setScore] = useState(null);
|
const [score, setScore] = useState(null);
|
||||||
const [gameTime, setGameTime] = useState(0);
|
const [gameTime, setGameTime] = useState(0);
|
||||||
|
const [remainingQuestionsAmount, setRemainingQuestionsAmount] = useState(null);
|
||||||
|
|
||||||
// ##### INTERFACE #####
|
// ##### INTERFACE #####
|
||||||
const [hasCheckedTutorial, setHasCheckedTutorial] = useState(false);
|
const [hasCheckedTutorial, setHasCheckedTutorial] = useState(false);
|
||||||
|
|
@ -34,6 +35,7 @@ export function GameContextProvider({ children }) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!contextGameDatas) return;
|
if (!contextGameDatas) return;
|
||||||
initAnswers();
|
initAnswers();
|
||||||
|
setRemainingQuestionsAmount(contextGameDatas.gameObjects.length);
|
||||||
}, [contextGameDatas]);
|
}, [contextGameDatas]);
|
||||||
|
|
||||||
function initAnswers() {
|
function initAnswers() {
|
||||||
|
|
@ -53,7 +55,7 @@ export function GameContextProvider({ children }) {
|
||||||
newAnswers[answerKey].userAnswer = answer;
|
newAnswers[answerKey].userAnswer = answer;
|
||||||
newAnswers[answerKey].userAnsweredCorrectly = answer === newAnswers[answerKey].correctAnswer;
|
newAnswers[answerKey].userAnsweredCorrectly = answer === newAnswers[answerKey].correctAnswer;
|
||||||
setAnswers(newAnswers);
|
setAnswers(newAnswers);
|
||||||
|
setRemainingQuestionsAmount(remainingQuestionsAmount - 1);
|
||||||
const newScore = calculateScore(answers);
|
const newScore = calculateScore(answers);
|
||||||
setScore(newScore);
|
setScore(newScore);
|
||||||
setCurrentGameModal(<GameAnswerExplanation questionId={answerKey} />);
|
setCurrentGameModal(<GameAnswerExplanation questionId={answerKey} />);
|
||||||
|
|
@ -117,6 +119,7 @@ export function GameContextProvider({ children }) {
|
||||||
initAnswers,
|
initAnswers,
|
||||||
isSoundOn,
|
isSoundOn,
|
||||||
setIsSoundOn,
|
setIsSoundOn,
|
||||||
|
remainingQuestionsAmount,
|
||||||
buildGameStatsObject,
|
buildGameStatsObject,
|
||||||
answerQuestion,
|
answerQuestion,
|
||||||
hasCheckedTutorial,
|
hasCheckedTutorial,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user