Skip to content

Commit

Permalink
x sound time and x show time consistend and made it a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
pireu2 committed Sep 29, 2023
1 parent 80e1260 commit dc1ff89
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/screens/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import '../static/styles/home.css';
import { useParams } from 'react-router-dom';
import useGame from '../hooks/useGame';
import QuestionsService from '../services/questions.service';
import wrongAnswerSound from '../static/x.mp3';
import wrongAnswerPng from '../static/x.png';
import { truncateQuestion } from '../helpers/truncate-question';
import { useSounds } from '../hooks/useSounds.hook';
import { WRONG_ANSWER_TIME } from '../utils/contants';

const Game = () => {
const [currentQuestion, setCurrentQuestion] = useState<DBQuestion>();
Expand All @@ -37,12 +36,11 @@ const Game = () => {
if (game?.wrongAnswer === 0) {
return;
}
const audio = new Audio(wrongAnswerSound);
setWrongAnswers(Math.min(3, game.wrongAnswer));

setTimeout(() => {
setWrongAnswers(0);
}, 2000);
}, WRONG_ANSWER_TIME);
}, [game?.wrongAnswer]);

useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/shared/GameRound/GameRoundAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useSounds } from '../../hooks/useSounds.hook';
import round_start from '../../static/round_start.mp3';
import correct_answer from '../../static/correct_answer.mp3';
import wrongAnswerSound from '../../static/x.mp3';
import { WRONG_ANSWER_TIME } from '../../utils/contants';

const GameRoundAdmin = (props: any) => {
const [questions, setQuestions] = useState<DBQuestion[]>([]);
Expand Down Expand Up @@ -103,7 +104,7 @@ const GameRoundAdmin = (props: any) => {

const setAllWrong = () => {
if (counterWrongAnswers != 3){
playSound(wrongAnswerSound, 5000);
playSound(wrongAnswerSound, WRONG_ANSWER_TIME);
}
GamesService.update(selectedGame, {
...game,
Expand Down Expand Up @@ -395,7 +396,7 @@ const GameRoundAdmin = (props: any) => {
onClick={() => {
setCounterWrongAnswers((prevState) => Math.min(prevState + 1, 3))
if (counterWrongAnswers <= 3){
playSound(wrongAnswerSound, 5000);
playSound(wrongAnswerSound, WRONG_ANSWER_TIME);
}
}}
style={{ marginRight: 10 }}
Expand Down
1 change: 1 addition & 0 deletions src/utils/contants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export enum environmentType {

export const TIMER_LENGTH = 20;
export const TIMER_BONUS = 5;
export const WRONG_ANSWER_TIME = 3000;

0 comments on commit dc1ff89

Please sign in to comment.