-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.js
38 lines (33 loc) · 1.01 KB
/
score.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* var sname="m_score"; */
function mAddScore(val){
scores = JSON.parse(localStorage[sname]);
if (!scores){ scores = []; }
name = prompt("What is your name?");
v = val.toString();
p = new Array(5-v.length+1).join("0");
scores.push(p+val.toString()+" "+name);
scores.sort();
localStorage[sname] = JSON.stringify(scores.slice(-10));
}
function mShowScore(){
s = JSON.parse(localStorage[sname]); s.sort();
ss = "Scoreboard\n----------\n";
n = s.length; while(n--){
ss += s[n]+"\n";
}
alert(ss);
}
function endGame2(gname, score){
ctx.clearRect(0, 0, cvs.width, cvs.height);
ctx.fillStyle = "#000000";
ctx.font = "bold 30px Arial";
ctx.fillText(gname, 20, cvs.height/2 - 20);
ctx.font = "30px Arial";
ctx.fillText("Score: "+score.toString(), 50, cvs.height/2 + 20);
mAddScore(score);
mShowScore();
cvs.onclick = init;
}
if (!localStorage[sname]){
localStorage[sname] = JSON.stringify([]);
}