-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreManager.js
50 lines (39 loc) · 1.21 KB
/
scoreManager.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
42
43
44
45
46
47
48
49
50
function ScoreManager(descr) {
for (var property in descr) {
this[property] = descr[property];
}
this.bossScoreRange = [150, 200, 300, 800];
this.scoreTable = {
"charger": [],
"convoy": []
};
this.playerScore = 0;
this.highScore = localStorage.getItem("highscore") || 0;
}
ScoreManager.prototype.addToScoreTable = function (mode, value) {
this.scoreTable[mode].push(value);
}
ScoreManager.prototype.getFromScoreTable = function (mode, type) {
return this.scoreTable[mode][type];
}
ScoreManager.prototype.setRandomBossScore = function () {
let index = util.randRange(0, 4);
this.scoreTable.charger[3] = this.bossScoreRange[index];
}
ScoreManager.prototype.increasePlayerScore = function (mode, type) {
this.playerScore += this.scoreTable[mode][type];
if (this.playerScore > this.highScore) {
this.highScore = this.playerScore;
localStorage.setItem("highscore", this.playerScore);
}
}
ScoreManager.prototype.getPlayerScore = function () {
return this.playerScore;
}
ScoreManager.prototype.getHighScore = function () {
return this.highScore;
}
ScoreManager.prototype.reset = function () {
this.playerScore = 0;
this.highScore = localStorage.getItem("highscore") || 0;
}