-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtilegame.js
105 lines (92 loc) · 2.16 KB
/
tilegame.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
function fnc(){
for(i=0;i<16;i++){
document.getElementById(i).disabled=false;
}
reset_time();
var a=new Array(9)
a=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
var j=0;
t=16;
var random;
var spacing="<br>";
while (j<a.length){
random=Math.floor(Math.random()*a.length)
if(a[random]!="slctd"){
document.getElementById(a[random]).value=j;
a[random]="slctd";
j++;
}
}
start();
}
var t=16;
var y=0;
var i;
var d;
function val(d=this.id){
if(document.getElementById(d).value==0){
y=0;
}
if(document.getElementById("st").disabled==false){
document.getElementById("st").disabled=true;
}
if(document.getElementById(d).value==y){
if(t>40){
c=document.getElementById(d).value="";
document.getElementById(d).disabled=true;
t++;
}
else{
document.getElementById(d).value=t;
t++;
}
if(t>56){
reset();
}
y++;
}
else{
for(i=0;i<16;i++){
document.getElementById(i).disabled=true;
}
reset();
}
}
function reset(){
document.getElementById("st").disabled=false;
stop();
}
var x,timer,divide;
x=0;
divide=1000;
var best_time=localStorage.getItem("best_time");
var curr_time;
function start(){
timer=self.setInterval("increment()",(1000/divide));
}
function increment(){
x++;
document.getElementById("timer_out").innerHTML=(x/divide);
if(best_time==null){
document.getElementById("best_time").innerHTML=(curr_time);
}
curr_time=x/divide;
}
function stop(){
if(t>56&&curr_time<(best_time)){
best_time=curr_time;
localStorage.setItem("best_time",best_time-0.001);
}
if(t>56&&best_time==null){
best_time=curr_time;
localStorage.setItem("best_time",best_time-0.001);
}
document.getElementById("best_time").innerHTML=(best_time);
clearInterval(timer);
timer=null;
}
function reset_time(){
stop();
x=0;
document.getElementById("timer_out").innerHTML=(x/divide);
}