Skip to content

Commit

Permalink
sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
spider4216 committed Jan 31, 2021
1 parent fcd0dcb commit b37a4ef
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jsx/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class App extends React.Component

let json = '[{"img":"/images/1/img.png", "title": "Russia"}, {"img":"/images/2/img.png", "title": "Kazakhstan"},{"img":"/images/3/img.png", "title": "Belarus"},{"img":"/images/4/img.png", "title": "China"},{"img":"/images/5/img.png", "title": "India"}]';

this.soundLoose = new Audio('sounds/loose.wav');
this.soundWin = new Audio('sounds/win.wav');
this.soundClock = new Audio('sounds/tick.wav');

this.data = JSON.parse(json);
let initialGuessData = this.data[this.random(this.data.length)];
// get initial state for img and answers
Expand Down Expand Up @@ -216,7 +220,12 @@ class App extends React.Component
let timer = setInterval(() => {
this.setState({time: this.state.time - 1});

if (this.state.time <= 5 && this.state.time > 0) {
this.soundClock.play();
}

if (this.state.time <= 0 && this.state.incorrect > 0) {
this.soundLoose.play();
this.restart(this.state.incorrect - 1, this.state.correct);
}

Expand Down Expand Up @@ -262,9 +271,11 @@ class App extends React.Component
}

if (this.state.answers[this.state.selected - 1].state == 'correct') {
this.soundWin.play();
this.setState({correct: this.state.correct + 1});

} else {
this.soundLoose.play();
this.setState({incorrect: this.state.incorrect - 1});

if (this.state.incorrect <= 0) {
Expand Down
Binary file added sounds/loose.wav
Binary file not shown.
Binary file added sounds/tick.wav
Binary file not shown.
Binary file added sounds/win.wav
Binary file not shown.

0 comments on commit b37a4ef

Please sign in to comment.