-
Notifications
You must be signed in to change notification settings - Fork 1
/
MatchingGamePart4.html
97 lines (70 loc) · 2.76 KB
/
MatchingGamePart4.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
<!DOCTYPE html>
<html>
<head>
<title>Matching Game</title>
<style>
#leftSide{
position: relative;
width:500px;
height: 500px;
float: left;
}
#rightSide {
width:500px;
height:500px;
left: 500px;
position: absolute;
border-left: 1px solid black;
}
</style>
</head>
<body>
<h1> MATCHING GAME </h1>
<p>
Click on the extra smiling face on left side.
</p>
<div id="leftSide">
</div>
<div id="rightSide"></div>
<script>
var numberOfFaces=5;
var score=0;
var leftSide=document.getElementById("leftSide");
window.onload=generateFaces;
function generateFaces(){
for(var i =0; i<numberOfFaces; i++){
var x= document.createElement("img");
x.setAttribute("src", "smile.png");
x.style.display='';
x.style.position='absolute';
x.style.top=Math.floor(Math.random()*400)+'px';
x.style.left=Math.floor(Math.random()*400) +'px';
var y=document.getElementById("leftSide");
y.appendChild(x);
}
var rightSide=document.getElementById("rightSide");
var leftSideImages=leftSide.cloneNode(true);
leftSideImages.removeChild(leftSideImages.lastChild);
rightSide.appendChild(leftSideImages);
var theBody=document.getElementsByTagName("body")[0];
leftSide.lastChild.onclick=function nextlevel(event){
event.stopPropagation();
numberOfFaces+=5;
score+=1;
while(leftSide.firstChild ){
leftSide.removeChild(leftSide.firstChild);
}
while(rightSide.firstChild ){
rightSide.removeChild(rightSide.firstChild);
}
generateFaces();
}
theBody.onclick=function(){
alert("GAME OVER!!\n Your SCORE:"+score);
theBody.onclick=null;
leftSide.onclick=null;
}
}
</script>
</body>
</html>