NDI-2019/Jeux_404/scores.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-12-06 01:43:54 +01:00
//VARIABLES
2019-12-06 04:12:43 +01:00
var premier = localStorage.setItem('premier', 0);
var deuxieme = localStorage.setItem('deuxieme', 0);
var troisieme = localStorage.setItem('troisieme', 0);
2019-12-06 01:43:54 +01:00
var tableau = {
canvas: document.createElement("canvas"),
start: function() {
this.canvas.width = 200;
this.canvas.height = 150;
2019-12-06 04:12:43 +01:00
var ctx = this.canvas.getContext("2d");
this.canvas.style = "position:absolute; margin-top: +50px; border: 2px solid #0d0d0d;";
2019-12-06 01:43:54 +01:00
document.body.insertBefore(this.canvas, document.body.childNodes[0]);
this.interval = setInterval(updateGameArea, 20);
},
clear: function() {
2019-12-06 04:12:43 +01:00
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
2019-12-06 01:43:54 +01:00
}
}
//METHODES
function update(score) {
if (score > premier)
2019-12-06 04:12:43 +01:00
localStorage.setItem('premier', score);
2019-12-06 01:43:54 +01:00
else if (score > deuxieme)
2019-12-06 04:12:43 +01:00
localStorage.setItem('deuxieme', score);
else if (score > troisieme)
localStorage.setItem('troisieme', score);
2019-12-06 01:43:54 +01:00
}
function load() {
2019-12-06 04:12:43 +01:00
update(getScore());
2019-12-06 01:43:54 +01:00
tableau.start();
2019-12-06 04:12:43 +01:00
}
//GETTER
function getPremier() {
return localStorage.getItem('premier');
}
function getSecond() {
return localStorage.getItem('deuxieme');
}
function getTroisieme() {
return localStorage.getItem('troisieme');
2019-12-06 01:43:54 +01:00
}