-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
161 lines (124 loc) · 3.52 KB
/
index.html
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
<script>
var array = [
{ thumbnail:'img/9ba25796112cad616be27e473ae1e149.jpg'},
{ thumbnail:'img/9ba25796112cad616be27e473ae1e149.jpg'},
{ thumbnail:'img/220px-Goofy.svg.png'},
{ thumbnail:'img/220px-Goofy.svg.png'},
{ thumbnail:'img/4420364-cartoon-characters.png'},
{ thumbnail:'img/4420364-cartoon-characters.png'},
{ thumbnail:'img/images.jpg'},
{ thumbnail:'img/images.jpg'},
{ thumbnail:'img/images.png'},
{ thumbnail:'img/images.png'},
{ thumbnail:'img/ce5f53437e291c48705428721406985c.jpg'},
{ thumbnail:'img/ce5f53437e291c48705428721406985c.jpg'}
];
/*var array=['a','b','c','a','b','c'];*/
var values = [];
var ids = [];
var set=[];
var flipped = 0;
var counter=0;
Array.prototype.memory_tile_shuffle = function(){
var i = array.length, j, temp;
while(--i > 0){
j = Math.floor(Math.random() * (i+1));
temp = array[j];
array[j] = array[i];
array[i] = temp;
}
}
function new1(){
flipped = 0;
var output = '';
array.memory_tile_shuffle();
for(var i = 0; i < array.length; i++){
output += '<img src="img/Donald-Duck-Iconic.jpg" id="tile_'+i+'" onclick="memoryFlipTile(tile_'+i+',\''+array[i].thumbnail+'\',this)" >'; }
document.getElementById('cartoon').innerHTML = output;
}
function memoryFlipTile(tile,val,at){
if(tile.innerHTML == "" && values.length < 2){
tile.style.background = 'white';
at.src=val;
if(values.length == 0){
values.push(val);
ids.push(tile.id);
set.push("0");
} else if(values.length == 1){
values.push(val);
ids.push(tile.id);
set.push("0");
if(values[0] == values[1]){
coun();
flipped += 2;
values = [];
ids = [];
if(flipped == array.length){
alert("won");
document.getElementById('cartoon').innerHTML = "";
document.getElementById('cnt').innerHTML = '0';
new1();
}
} else {
function flip2Back(){
coun();
var tile_1 = document.getElementById(ids[0]);
var tile_2 = document.getElementById(ids[1]);
tile_1.style.background = 'white';
tile_1.src = "img/Donald-Duck-Iconic.jpg";
tile_2.style.background = 'white ';
tile_2.src = "img/Donald-Duck-Iconic.jpg";
values = [];
ids = [];
}
setTimeout(flip2Back, 200);
}
}
}
}
function coun(){
counter++;
document.getElementById('cnt').innerHTML = counter;
if(counter == 1){
second = 0;
minute = 0;
hour = 0;
startTimer();
}
var second = 0, minute = 0; hour = 0;
var interval;
function startTimer(){
if(flipped != array.length){
interval = setInterval(function(){
document.getElementById("timer") .innerHTML= minute+"mins "+second+"secs";
second++;
if(second == 60){
minute++;
second=0;
}
if(minute == 60){
hour++;
minute = 0;
}
},1000);
}
}
}
</script>
</head>
<body style="background-color: aquamarine">
<h1> Memory Game</h1>
<div id="cartoon"></div>
<script>new1();</script>
<div class="points">
<div class="ctr">
<h1>Moves: <span id="cnt">0</span></h1>
</div>
<div class="ti"><h1>Time: <span id="timer">00mins 00secs</span></h1></div>
</div>
</body>
</html>