-
Notifications
You must be signed in to change notification settings - Fork 10
/
GameState.js
46 lines (38 loc) · 1.15 KB
/
GameState.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
gameApp.factory("GameState", function(GlobalSettings) {
return {
score: 0,
highScore: 0,
level: 1,
lives: GlobalSettings.lives,
gameState: GameStateEnum.GameActive,
isPlayerAlive: function() {
return this.lives > 0;
},
isGameOver: function() {
return this.gameState === GameStateEnum.GameOver;
},
isCurrentLevelHighSpeed: function() {
return this.level % 2 == 0;
},
reset: function() {
this.lives = GlobalSettings.lives;
this.level = 1;
this.score = 0;
this.gameState = GameStateEnum.GameActive;
},
incrementScore: function(increment) {
this.score += increment;
if (this.score > this.highScore) {
this.highScore = this.score;
}
},
die: function() {
if (this.lives > 0) {
this.lives--;
}
if (this.lives === 0) {
this.gameState = GameStateEnum.GameOver;
}
}
}
});