-
Notifications
You must be signed in to change notification settings - Fork 0
/
matching_final.html
69 lines (66 loc) · 1.82 KB
/
matching_final.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
<!DOCTYPE html>
<html>
<head>
<title>
Matching Game
</title>
<script type="text/javascript">
var numberOfFaces = 5;
var theLeftSide = document.getElementById("leftside");
var theBody = document.getElementsByTagName("body")[0];
function generatefaces() {
var theBody = document.getElementsByTagName("body")[0];
for (var i = 0; i < numberOfFaces; i++) {
var theBody = document.getElementsByTagName("body")[0];
var theLeftSide = document.getElementById("leftside");
var theRightSide = document.getElementById("rightside");
var left_img = document.createElement("IMG");
left_img.src = "http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png";
top1 = Math.floor(Math.random()*401);
left_img.style.top = top1 + "px";
left = Math.floor(Math.random()*401);
left_img.style.left = left + "px";
theLeftSide.appendChild(left_img);}
var leftimg = theLeftSide.cloneNode(true);
leftimg.removeChild(leftimg.lastChild)
theRightSide.appendChild(leftimg);
theLeftSide.lastChild.onclick = function nextLevel(event){
event.stopPropagation();
numberOfFaces += 5;
while(theLeftSide.firstChild)
theLeftSide.removeChild(theLeftSide.firstChild);
while(theRightSide.firstChild)
theRightSide.removeChild(theRightSide.firstChild);
generatefaces();
};
theBody.onclick = function gameOver() {
alert("Game Over!");
theBody.onclick = null;
theLeftSide.lastChild.onclick = null;
};
}
</script>
</head>
<style type="text/css">
img{
position: absolute;
}
div{
position: absolute;
width: 500px;
height: 500px;
}
#rightside {left: 500px;
border-left: 1px solid black;
text
}
</style>
<body onload= "generatefaces()">
<h3>Matching Game</h3>
<p>Click on the extra smiling face on the left</p>
<div id="leftside">
</div>
<div id="rightside">
</div>
</body>
</html>