Skip to content

Commit

Permalink
Fix answer question double shot
Browse files Browse the repository at this point in the history
  • Loading branch information
hueckidom committed Aug 21, 2024
1 parent c643d39 commit 50ab045
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions client/src/views/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ const GameField: React.FC<any> = () => {
}, [gameStared]);

useEffect(() => {
// if (life <= 0) {
// window.location.href = `/#/enter-score`;
// }
if (life <= 0) {
window.location.href = `/#/enter-score`;
}
}, [life]);

useEffect(() => {
Expand Down Expand Up @@ -411,8 +411,9 @@ const GameField: React.FC<any> = () => {
};

const handleGoal = () => {
setLife((prevLife) => prevLife - 1);
if (life > 0) {
const newLife = gameState().life! - 1;
setLife(newLife);
if (newLife > 0) {
playSound(goalSound);
resetBall();
} else {
Expand Down Expand Up @@ -537,7 +538,9 @@ const GameField: React.FC<any> = () => {
};

const answeredQuestion = (questionIndex: number) => {
gameHub.pushAnsweredQuestion(gameState().sessionId!, { questionIndex });
if (gameState().isHost) {
gameHub.pushAnsweredQuestion(gameState().sessionId!, { questionIndex });
}
};

const handleAnswer = (isCorrect: boolean) => {
Expand All @@ -547,7 +550,7 @@ const GameField: React.FC<any> = () => {
if (isCorrect) {
setScore(gameState().score! + timer);
} else {
setLife((prevLife) => prevLife - 1);
setLife(gameState().life! - 1);
}
}

Expand Down

0 comments on commit 50ab045

Please sign in to comment.