-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameover.js
85 lines (72 loc) · 1.84 KB
/
gameover.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"use strict";
(function()
{
//automatically called as soon as the javascript is loaded
window.addEventListener("load", main);
}());
var audio, gameovers;
function main() {
var doneBtn = document.getElementById("doneBtn");
var muted = sessionStorage.getItem("muted");
var volume = parseFloat(sessionStorage.getItem("volume"));
audio = document.getElementsByTagName('audio')[0];
var coins = sessionStorage.getItem("coins");
if(muted == null){
muted="false";
sessionStorage.setItem("muted",muted);
}
if(volume >=0 && isNaN(volume)==false){
audio.volume=volume;
}else{
volume=0.5;
audio.volume=volume;
}
if(muted == "true"){
audio.volume=0;
}else if (muted =="false"){
audio.volume=volume;
}
audio.play();
var bch = function(event)
{
btnHandler(event);
}
doneBtn.addEventListener("click",bch);
}
function btnHandler(event)
{
var top;
var nick = document.getElementById("nickName").value;
if(nick == "")
{
nick = "Unknown";
}
while(nick.length > 24){
alert("Nickname too long. Must have 0 to 24 characters!");
window.location.href = "gameover.html";
return;
}
var score = parseInt(sessionStorage.getItem("score"));
for(var i = 1; i<11; i++) {
if(score > parseInt(sessionStorage.getItem(i)))
{
if(i != 10) {
for(var j = 10; j>i; j--) {
sessionStorage.setItem(j,sessionStorage.getItem((j-1)));
sessionStorage.setItem(j+"nick",sessionStorage.getItem((j-1)+"nick"));
}
}
sessionStorage.setItem(i,score);
sessionStorage.setItem(i+"nick",nick);
top = true;
break;
}
}
if(top) {
alert("Congratulations! You made it to the top 10!");
}
else {
alert("Sorry you didn't make it to the top 10, better luck next time!")
}
window.location.href = "rankingmenu.html";
}