HTML5 2D 游戏开发 结束游戏(8)显示得分
 
- UID
- 1066743
|

HTML5 2D 游戏开发 结束游戏(8)显示得分
显示得分游戏结束后,Snail Bait 将会显示得分,如图 9 所示:
图 9. 在游戏结束时显示得分 显示和隐藏得分的 Snail Bait 方法如清单 18 所示:
清单 18. 显示和隐藏得分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
| SnailBait.prototype = {
...
gameOver: function () {
snailBait.revealCredits();
},
restartGame: function () {
this.hideCredits();
this.lives = this.MAX_NUMBER_OF_LIVES;
this.updateLivesElement();
this.score = 0;
this.updateScoreElement();
},
revealCredits: function () {
this.creditsElement.style.display = 'block';
this.revealLivesIcons();
this.tweetElement.href = TWEET_PREAMBLE + this.score + TWEET_PROLOGUE;
setTimeout( function () {
snailBait.creditsElement.style.opacity = 1.0;
}, snailBait.SHORT_DELAY);
},
hideCredits: function () {
var CREDITS_REVEAL_DELAY = 2000;
this.creditsElement.style.opacity = this.TRANSPARENT;
setTimeout( function (e) {
snailBait.creditsElement.style.display = 'none';
}, this.CREDITS_REVEAL_DELAY);
},
};
|
Snail Bait 的 gameOver() 方法(由 loseLife() 方法调用,参见 )将会显示得分,而 restartGame() 方法将会隐藏得分。restartGame() 方法是由(与得分的 “再玩一次” 链接相关的)事件处理程序调用。事件处理程序如清单 19 所示:
清单 19. 得分屏幕事件处理程序1
2
3
| snailBait.newGameLink.onclick = function (e) {
snailBait.restartGame();
};
|
|
|
|
|
|
|