Skip to content

Commit

Permalink
experience and level
Browse files Browse the repository at this point in the history
  • Loading branch information
stdio2016 committed Aug 27, 2018
1 parent 2eb0f99 commit 39f0e9e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
17 changes: 17 additions & 0 deletions js/states/GameScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ GameScreen.prototype.updateOnce = function () {
if (this.board.state == Board.ENDED) {
var me = this;
if (promptCallback === doesNothing) {
me.saveScore(me.board.score);
alertBox("Time's up\nYour score: " + me.board.score + "\nPress OK to replay", function () {
me.state.start('MainMenu');
});
Expand Down Expand Up @@ -402,3 +403,19 @@ GameScreen.prototype.shutdown = function () {
window.board = null;
this.effectSprites = [];
};

GameScreen.prototype.saveScore = function (score) {
if (this.board.debug.autoSwipe) return ;
try {
var xp = +localStorage.ShapeClear_xp;
if (!xp) xp = 0;
xp += Math.floor(score / 10);
localStorage.ShapeClear_xp = xp;
var times = +localStorage.ShapeClear_played;
if (!times) times = 0;
localStorage.ShapeClear_played = times + 1;
}
catch (x) {
;
}
};
11 changes: 10 additions & 1 deletion js/states/MainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ MainMenu.prototype.create = function () {
this.title.anchor.set(0.5, 0.5);
this.title.inputEnabled = true;
this.title.events.onInputUp.add(function () {
var xp = localStorage.ShapeClear_xp || 0;
var times = localStorage.ShapeClear_played || 0;
var lv = 1;
var req;
while (lv < 50 && xp > (req = Math.floor(prank(lv+1, 40)) * 10)) {
lv++;
}
alertBox(
"Copyright (c) 2016~2018 Yi-Feng Chen(陳羿豐)\n" +
"Licensed under MIT license\n" +
"This game uses Phaser game engine"
"This game uses Phaser game engine\n" +
"Lv. " + lv + " xp: " + xp + "/" + req + "\n" +
"You played " + times + " times"
);
Debug.createSpecial ^= 1;
}, this);
Expand Down

0 comments on commit 39f0e9e

Please sign in to comment.