-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (120 loc) · 4.29 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="jquery-3.5.1.js"></script>
<script>
document.addEventListener("DOMContentLoaded",()=>{
const images = ["images/batman.jpg","images/blackpanther.jpg","images/blackwidow.jpg","images/captainamerica.jpg","images/captainmarvel.jpg",
"images/ironman.jpg","images/spiderman.jpg","images/theflash.jpg",
"images/batman.jpg","images/blackpanther.jpg","images/blackwidow.jpg","images/captainamerica.jpg","images/captainmarvel.jpg",
"images/ironman.jpg","images/spiderman.jpg","images/theflash.jpg"];
document.getElementsByTagName("input")[0].onclick = reset;
window.onload = display;
function display() {
$("img").each(function () {
// default source(hide the images)
$(this).attr("src", "images/cover.jpg");
for (let i = 0; i < 16; i++) {
blocks[i].setAttribute("id", i);
blocks[i].addEventListener("click", show);
}
});
}
var blocks = document.getElementsByTagName("img");
var opened = [];
var guessedCorrect = [];
function show()
{
opened.push(this);
this.src = images[this.id];
if(opened.length === 2)
{
if (opened[0].src === opened[1].src){
if(guessedCorrect.indexOf(opened[0])===-1) {
guessedCorrect.push(opened[0]);
}
opened = [];
}
}
if(opened.length === 3) {
opened[0].removeEventListener("click",show);
opened[1].removeEventListener("click",show);
opened[2].removeEventListener("click",show);
if (opened[0].src === opened[1].src){
if(guessedCorrect.indexOf(opened[0])===-1) {
guessedCorrect.push(opened[0]);
}
opened.shift();
opened.shift();
}
else{
close();
}
}
if(guessedCorrect.length === 8) {
setTimeout(gameOver, 500);
}
}
function gameOver()
{
alert("You found them all!");
reset();
}
function reset(){
opened = [];
guessedCorrect = [];
display();
}
function close()
{
opened[0].addEventListener("click",show);
opened[0].setAttribute("src","images/cover.jpg");
opened.shift();
}
})
</script>
<style>
td{
width: 250px;
height: 200px;
}
img{
width: 250px;
height: 200px;
}
</style>
</head>
<body>
<h1>Meморија</h1>
<div style="text-align:left; float:left">
<table border="1">
<tr>
<td id="11"><img src=""/></td>
<td id="12"><img src=""/></td>
<td id="13"><img src=""/></td>
<td id="14"><img src=""/></td>
</tr>
<tr>
<td id="21"><img src=""/></td>
<td id="22"><img src=""/></td>
<td id="23"><img src=""/></td>
<td id="24"><img src=""/></td>
</tr>
<tr>
<td id="31"><img src=""/></td>
<td id="32"><img src=""/></td>
<td id="33"><img src=""/></td>
<td id="34"><img src=""/></td>
</tr>
<tr>
<td id="41"><img src=""/></td>
<td id="42"><img src=""/></td>
<td id="43"><img src=""/></td>
<td id="44"><img src=""/></td>
</tr>
</table>
<input type="submit" value="RESET"/>
</div>
<br/>
</body>