/
stats.js
executable file
·41 lines (40 loc) · 1.03 KB
/
stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Stats {
constructor() {
this.matches = 0;
this.attempts = 0;
this.accuracy = 0;
this.gamesPlayed = 0;
this.gameReset = this.gameReset.bind(this);
}
displayStats() {
$('.games-played .value').text(this.gamesPlayed);
$('.attempts .value').text(this.attempts);
$('.accuracy .value').text(Math.round(this.accuracy * 100) + '%');
}
resetStats() {
this.matches = 0;
this.accuracy = 0;
this.attempts = 0;
this.displayStats();
}
accuracyCalculate(){
this.accuracy = this.matches / this.attempts;
}
displayWinModalandSound() {
$('#win-modal').css('display', 'block');
music.startAudio('win');
}
gameReset() {
game.matchCounter = 0;
game.firstCardClicked = null;
game.secondCardClicked = null;
this.gamesPlayed++;
this.resetStats();
this.displayStats();
$('.game-area').empty();
game.shuffleCards(game.images);
game.renderCards();
$('.game-area').on('click', '.back', game.cardClicked);
$('#win-modal').css('display', 'none');
}
}