-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.js
112 lines (96 loc) · 1.94 KB
/
game.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
gamelength=30;
timerID=null
var playing=false;
var numholes=4*4;
var currentpos=-1;
function clrholes() {
for(var k=0;k<numholes;k++)
{
var a=document.getElementById("button"+k);
a.setAttribute("style", "background-image:url('button-inactive.png')");
a.setAttribute("data-checked","0");
}
}
function stoptimer() {
if(playing)
clearTimeout(timerID);
}
function showtime(remtime) {
document.cpanel.timeleft.value=remtime;
if(playing) {
if(remtime==0) {
stopgame();
return;
}
else {
temp=remtime-1;
timerID=setTimeout("showtime(temp)",1000);
}
}
}
function stopgame() {
stoptimer();
playing=false;
document.cpanel.timeleft.value=0;
clrholes();
sendGameResult("Iolanta-Hotoboc",totalhits)
alert('Game Over.\nYour score is: '+totalhits);
}
function play() {
stoptimer();
if(playing) {
stopgame();
return;
}
playing=true;
clrholes();
totalhits=0;
document.cpanel.score.value=totalhits;
launch();
showtime(gamelength);
}
function launch() {
var launched=false;
while(!launched) {
mynum=random();
if(mynum!=currentpos) {
document.getElementById("button"+mynum).setAttribute("data-checked","1");
document.getElementById("button"+mynum).setAttribute("style","background-image:url('button-active.png')");
currentpos=mynum;
launched=true;
}
}
}
function hithead(id) {
if(playing==false) {
clrholes();
return;
}
if(currentpos!=id) {
totalhits+=-1;
document.cpanel.score.value=totalhits;
}
else {
totalhits+=1;
document.cpanel.score.value=totalhits;
launch();
document.getElementById("button"+id).setAttribute("data-checked","0");
document.getElementById("button"+id).setAttribute("style","background-image:url('button-inactive.png')");
}
}
function random() {
return(Math.floor(Math.random()*100%numholes));
}
//Donate Form
var donation;
function getdonation(x)
{
donation=x;
}
function setdonation()
{
var x;
x=document.getElementById('other').value;
if(+x!=0)
donation=+x;
}