-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
90 lines (80 loc) · 2.39 KB
/
index.html
File metadata and controls
90 lines (80 loc) · 2.39 KB
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Concentrating Adventure Time </title>
<script src="scripts/jquery.js"></script>
<script>
var boxFlipped=0;
var pairs=0;
var flippedImage=new Array(2);
var imagePath=new Array(18);
var randomNumber=Math.floor(1+Math.random()*(25-18));
var seconds=0;
for(i=0; i<36; i++){
if (i < 18) imagePath[i]="images\/"+(i+randomNumber)+".png";
else imagePath[i]="images\/"+(i-(18-randomNumber))+".png";
}
$( document ).ready( function() {
var timer0 = setInterval(function() {
$(".hid").text("Time: "+seconds+" s, and you've guessed "+pairs+" pairs of cards");
seconds++;
}, 1000);
confuseArray(imagePath);
for(i=0; i<36;i++){
$(".wrapper").append("<div id="+i+" class='box'><img id='img"+i+"' class='img' src="+imagePath[i]+">")
}
$( ".box" ).click( function() {
console.log("you've just clicked box with id:"+$(this).attr('id'));
if($( "#img"+$(this).attr('id') ).css("display")=="none" && boxFlipped<2){
flippedImage[boxFlipped] = $( "#img"+$(this).attr('id') );
flippedImage[boxFlipped].show();
boxFlipped++;
if ( flippedImage[0].attr('src')==flippedImage[1].attr('src') && flippedImage[0].attr('id')!=flippedImage[1].attr('id') ) {
pairs++;
boxFlipped =0;
if (pairs == 18) {
clearInterval(timer0);
$(".hid").text("You win, time:"+seconds+"s, you've guessed all pairs");
}
}
} else {
flippedImage[0].hide();
flippedImage[1].hide();
flippedImage[0]=null;
flippedImage[1]=null;
boxFlipped = 0;
}
})
})
function confuseArray(array){
var a,b,r1,r2;
for(i=0; i<array.length; i++){
r1=Math.floor(Math.random()*array.length);
r2=Math.floor(Math.random()*array.length);
a = array[r1];
b = array[r2];
array[r1] = b;
array[r2] = a;
}
//return array;
}
</script>
<style>
.wrapper { width:920px; margin:0 auto; }
.box { width:150px; height:150px; float:left; margin:1px; color: #333; background:#333;}
.hid { font-size: x-large; text-align:center; width:910px; margin: 0 auto; height:50px; border: solid 1px red}
.img {
display: none;
width: 150px;
height: 150px;
}
.col1 { background:yellow; }
.col2 { background:red; }
</style>
</head>
<body>
<div class="hid"> </div>
<div class="wrapper"> </div>
</body>
</html>