From 7c2ce752ee009a23dc12a7d8c56713916cac2165 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 22 Aug 2018 10:29:14 +0200 Subject: [PATCH] Using localStorage to keep the high score --- src/scene.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/scene.js b/src/scene.js index 937a110..230339a 100644 --- a/src/scene.js +++ b/src/scene.js @@ -1,9 +1,9 @@ class Scene extends Screen { + constructor(canvas, player) { super(canvas); this.player = player; this.currentHeight = 0; - this.maxHeight = 0; this.initialize(); 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() { super.initialize(); this.player.reset(); @@ -20,6 +28,10 @@ class Scene extends Screen { this.currentHeight = 0; this.started = false; + if (this.maxHeight === undefined) { + this.maxHeigth = 0; + } + // Generate random initial platforms for (let i = 0.25; i <= 2; i += 0.33) { let platform = new Platform(Math.random(), i, 0.2);