-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
135 lines (126 loc) · 3.28 KB
/
script.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
124
125
126
127
128
129
130
131
132
133
134
135
var plaatjes = [];
var count = 0;
var rp = [];
var randomized = [];
var naam;
var hiders;
var selected = [];
var gevonden = [];
var images = document.getElementsByTagName('img');
var av;
if (document.getElementById('av')) {av = document.getElementById('av').value} else {av = 42}
function startMemo() {
document.getElementById('hider').innerHTML = "";
for (i=0; i<av; i++) {
new plaatje("hider", i);
}
for (i=1; i<(0.5 * av + 1); i++) { //aantal setjes
plaatjes.push(i);
plaatjes.push(i);
}
randomizer();
for (i=0; i<av; i++) {
new plaatje(randomized[i], i);
}
check();
}
function geklikt(lv) {
if (lv.src != "http://timklein.tk/games/memory/doorzichtig.png") {
//console.log(lv.src);
lv.src = "http://timklein.tk/games/memory/doorzichtig.png";
selected.push(lv);
if (selected[0] && selected[1] && document.getElementById("p" + selected[0].id.substr(1)).src == document.getElementById("p" + selected[1].id.substr(1)).src) {
gevonden.push(selected[0]);
gevonden.push(selected[1]);
selected.shift();
selected.shift();
} else
if (selected.length > 2) {
selected[0].src = "http://timklein.tk/games/memory/achterkant.jpg";
selected[1].src = "http://timklein.tk/games/memory/achterkant.jpg";
selected.shift();
selected.shift();
}
}
}
function randomizer() {
for (i = 0; i < av; i++) { //aantal kaartjes totaal
rp[Math.floor(Math.random()*1000)] = plaatjes[i];
}
for (i=0; i<1000; i++) {
if (rp[i]) {
randomized.push(rp[i]);
}
}
}
function plaatje(id, num) {
if (id == "hider") {
this.image = new Image();
this.image.src = "http://timklein.tk/games/memory/achterkant.jpg";
// this.image.class = "logo";
this.image.addEventListener("click", function() {geklikt(this)});
this.image.id = "h" + num;
this.image.className = "plaatje";
document.getElementById('hider').appendChild(this.image);
}else {
this.image = new Image();
this.image.src = "http://timklein.tk/games/memory/plaatje" + id + ".jpg";
document.getElementById('wrapper').appendChild(this.image);
this.image.id = "p" + num;
this.image.className = "plaatje";
}
}
function check() {
if (randomized.length != av) {
randomized = [];
rp = [];
plaatjes = [];
while (images.length > 0) {
images[0].parentNode.removeChild(images[0]);
}
startMemo();
}
}
function restart() {
while (gevonden[0]) {
gevonden[0].src = "http://timklein.tk/games/memory/achterkant.jpg";
gevonden.shift();
}
while (selected[0]) {
selected[0].src = "http://timklein.tk/games/memory/achterkant.jpg";
selected.shift();
}
randomized = [];
rp = [];
plaatjes = [];
while (images.length > 0) {
images[0].parentNode.removeChild(images[0]);
}
av = document.getElementById('av').value;
sizeChange(av);
startMemo();
}
function sizeChange(size) {
console.log("hoi" + size);
var x;
switch (size) {
case "16":
x = 416;
console.log("16");
break;
case "20":
x = 520;
break;
case "24":
case "30":
case "36":
x = 624;
break;
case "28":
case "42":
x = 728;
break;
}
document.getElementById('hider').style.width = x +"px";
document.getElementById('wrapper').style.width = x +"px";
}