-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.js
103 lines (92 loc) · 2.03 KB
/
memory.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
var total = 16; //number of cards
var speed = 150;
var returnSec = 1000;
var cat = [];
var index;
var first = true;
var card1;
var card2;
var pair = 0;
//cardClose
function cardClose(i,n){
$("#card li:eq("+i+")").stop().animate({ left: "75"}, speed);
$("#card li:eq("+i+") img").stop().animate({ width: "0",height: "80px"}, speed,
function(){
n(i);
});
}
//omoteOpen
function omoteOpen(){
$("#card li:eq("+index+") img").attr("src","img/card"+cat[index]+".png");
$("#card li:eq("+index+") img").stop().animate({ width: "80px",height: "80px"}, speed);
$("#card li:eq("+index+")").stop().animate({ left: "0"}, speed);
}
//uraOpen
function uraOpen(j){
$("#card li:eq("+j+") img").attr("src","img/card.png");
$("#card li:eq("+j+") img").stop().animate({ width: "80px",height: "80px"}, speed);
$("#card li:eq("+j+")").stop().animate({ left: "0"}, speed);
}
//cardlock
function cardlock(){
$("#card li:eq("+index+")").addClass("lock");
}
//alllock
function alllock(){
$("#card li").addClass("lock");
}
//unlock
function unlock(){
$("#card li").removeClass("lock");
}
//comparison
function comparison() {
if(card1==card2){
$("#card li:eq("+index+")").addClass("off");
$("#card li:eq("+index1+")").addClass("off");
pair++;
if(pair==total/2){
setTimeout(function(){
alert("cleared !")
}, returnSec);
}
} else {
setTimeout(function(){
cardClose(index,uraOpen);
cardClose(index1,uraOpen);
}, returnSec);
}
first = true;
card2 = 0;
setTimeout(function(){
unlock(); //unlock
}, returnSec+speed*2);
}
$(function(){
//array
for(i=1; i<=total/2; i++) {
cat.push(i,i);
}
//random
cat.sort(function() {
return Math.random() - Math.random();
});
//li tag
for(i=1; i<=total; i++) {
$("#card").append("<li><img src='img/card.png'></li>");
}
$("#card li").click(function(){
index = $("#card li").index(this);
cardlock();
cardClose(index,omoteOpen);
if(first == true){
index1 = index;
card1= cat[index];
first = false;
} else {
alllock();
card2 = cat[index];
comparison();
}
});
});