-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomboxs.js
123 lines (115 loc) · 3.22 KB
/
randomboxs.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
113
114
115
116
117
118
119
120
121
122
123
function GenerateRandomNumbers(){
mainRoot=document.getElementById("root");
tbody=document.createElement("tbody");
data_len=[];
correct_data=[];
var count=0;
for(var i=0;i<4;i++){
row=document.createElement("tr");
for(var j=0;j<4;j++){
col=document.createElement("td");
col.setAttribute("data-number","false");
//click event start here
col.addEventListener("click",function(e){
count+=1;
e.target.style.background="yellow";
data=e.target.getAttribute("data-number");
e.target.innerHTML=data;
e.target.style.pointerEvents='none';
data_len.push(e.target);
if(data_len.length>=2)
{
var enter=false;
for(var c=0;c<data_len.length;c++){
if(data_len[data_len.length-2].getAttribute("data-number")==e.target.getAttribute("data-number"))
{
e.target.style.pointerEvents='none';
data_len[data_len.length-2].style.pointerEvents='none';
data_len[data_len.length-2].setAttribute("data-revel","true");
e.target.setAttribute("data-revel","true");
data_len.splice(0,data_len.length);
enter=false;
}
else
{
data_len[data_len.length-2].style.pointerEvents='auto';
e.target.style.pointerEvents='auto';
enter=true
}
}
if(enter==true)
{
data_len.splice(0,data_len.length);
dom=document.querySelectorAll("table tr td");
if(count>=2){
for(var k=0;k<dom.length;k++)
{
dom[k].style.pointerEvents='none';
}
count=0;
setTimeout(function(){NumberToggle(e);},1000);
}
}
}
});
row.appendChild(col);
}
tbody.appendChild(row);
}
mainRoot.appendChild(tbody);
callRandom();
document.getElementById("generate").disabled = true;
}
function NumberToggle(e)
{
dom=document.querySelectorAll("table tr td");
data_count=[];
data=e.target.getAttribute("data-number");
for(var i=0;i<dom.length;i++)
{
dom[i].style.pointerEvents='auto';
if(dom[i].getAttribute("data-revel")=="true")
{
dom[i].style.pointerEvents='none';
dom[i].style.background="yellow";
data_count.push(dom[i]);
}
else
{
dom[i].style.background="aqua";
dom[i].innerHTML="";
}
}
successMessage();
}
function successMessage()
{
var levelCompleteCheck=false;
dom=document.querySelectorAll("table tr td");
count_data=[];
for(var i=0;i<dom.length;i++)
{
if(dom[i].getAttribute("data-revel")=="true")
{
count_data.push(dom[i]);
levelCompleteCheck=true
}
}
if(levelCompleteCheck==true && count_data.length>=12)
{
// alert("you win");
}
}
function callRandom(){
var arr=[0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7];
var data=document.querySelectorAll("table tr td");
for(var j=0;j<data.length;j++){
len=Math.floor(Math.random()*arr.length);
if(data[j].getAttribute('data-number')=="false"){
if(arr.length>0){
data[j].setAttribute('data-number',arr[len]);
arr.splice(len,1);
}
}
}
}