From 50ab04550fc7832f965593888fd17d9fffb504e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCcki?= Date: Wed, 21 Aug 2024 13:51:52 +0200 Subject: [PATCH] Fix answer question double shot --- client/src/views/Game.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/client/src/views/Game.tsx b/client/src/views/Game.tsx index 88d98c4..b0a3be7 100644 --- a/client/src/views/Game.tsx +++ b/client/src/views/Game.tsx @@ -175,9 +175,9 @@ const GameField: React.FC = () => { }, [gameStared]); useEffect(() => { - // if (life <= 0) { - // window.location.href = `/#/enter-score`; - // } + if (life <= 0) { + window.location.href = `/#/enter-score`; + } }, [life]); useEffect(() => { @@ -411,8 +411,9 @@ const GameField: React.FC = () => { }; const handleGoal = () => { - setLife((prevLife) => prevLife - 1); - if (life > 0) { + const newLife = gameState().life! - 1; + setLife(newLife); + if (newLife > 0) { playSound(goalSound); resetBall(); } else { @@ -537,7 +538,9 @@ const GameField: React.FC = () => { }; const answeredQuestion = (questionIndex: number) => { - gameHub.pushAnsweredQuestion(gameState().sessionId!, { questionIndex }); + if (gameState().isHost) { + gameHub.pushAnsweredQuestion(gameState().sessionId!, { questionIndex }); + } }; const handleAnswer = (isCorrect: boolean) => { @@ -547,7 +550,7 @@ const GameField: React.FC = () => { if (isCorrect) { setScore(gameState().score! + timer); } else { - setLife((prevLife) => prevLife - 1); + setLife(gameState().life! - 1); } }