localStorage fixed for online

This commit is contained in:
Darkin 2019-10-20 18:08:45 +02:00
parent b6b38293b3
commit bea2628ed9

23
game.js
View file

@ -239,16 +239,23 @@
sctx.strokeText(this.score.curr,scrn.width/2,50); sctx.strokeText(this.score.curr,scrn.width/2,50);
break; break;
case state.gameOver : case state.gameOver :
this.score.best = Math.max(this.score.curr,localStorage.getItem("best"));
localStorage.setItem("best",this.score.best);
sctx.lineWidth = "2"; sctx.lineWidth = "2";
sctx.font = "40px Squada One"; sctx.font = "40px Squada One";
let sc = `SCORE : ${this.score.curr}` let sc = `SCORE : ${this.score.curr}`;
let bs = `BEST : ${this.score.best}` try {
sctx.fillText(sc,scrn.width/2-80,scrn.height/2); this.score.best = Math.max(this.score.curr,localStorage.getItem("best"));
sctx.strokeText(sc,scrn.width/2-80,scrn.height/2); localStorage.setItem("best",this.score.best);
sctx.fillText(bs,scrn.width/2-80,scrn.height/2+30); let bs = `BEST : ${this.score.best}`;
sctx.strokeText(bs,scrn.width/2-80,scrn.height/2+30); sctx.fillText(sc,scrn.width/2-80,scrn.height/2);
sctx.strokeText(sc,scrn.width/2-80,scrn.height/2);
sctx.fillText(bs,scrn.width/2-80,scrn.height/2+30);
sctx.strokeText(bs,scrn.width/2-80,scrn.height/2+30);
}
catch(e) {
sctx.fillText(sc,scrn.width/2-85,scrn.height/2+15);
sctx.strokeText(sc,scrn.width/2-85,scrn.height/2+15);
}
break; break;
} }
} }