Using localStorage to keep the high score

This commit is contained in:
Thomas Forgione 2018-08-22 10:29:14 +02:00
parent c398ba3087
commit 7c2ce752ee
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 13 additions and 1 deletions

View File

@ -1,9 +1,9 @@
class Scene extends Screen { class Scene extends Screen {
constructor(canvas, player) { constructor(canvas, player) {
super(canvas); super(canvas);
this.player = player; this.player = player;
this.currentHeight = 0; this.currentHeight = 0;
this.maxHeight = 0;
this.initialize(); this.initialize();
this.addEventListener('touchstart', (event) => { this.addEventListener('touchstart', (event) => {
@ -11,6 +11,14 @@ class Scene extends Screen {
}); });
} }
get maxHeight() {
return window.localStorage.getItem("maxHeight");
}
set maxHeight(value) {
window.localStorage.setItem("maxHeight", value);
}
initialize() { initialize() {
super.initialize(); super.initialize();
this.player.reset(); this.player.reset();
@ -20,6 +28,10 @@ class Scene extends Screen {
this.currentHeight = 0; this.currentHeight = 0;
this.started = false; this.started = false;
if (this.maxHeight === undefined) {
this.maxHeigth = 0;
}
// Generate random initial platforms // Generate random initial platforms
for (let i = 0.25; i <= 2; i += 0.33) { for (let i = 0.25; i <= 2; i += 0.33) {
let platform = new Platform(Math.random(), i, 0.2); let platform = new Platform(Math.random(), i, 0.2);