-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatching_game_js.js
34 lines (33 loc) · 1.23 KB
/
matching_game_js.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
var numberOfFaces = 5;
var theLeftSide = document.getElementById("leftSide");
var theRightSide = document.getElementById("rightSide");
var theBody = document.getElementsByTagName("body")[0];
function generateFaces() {
while (theLeftSide.firstChild) {
theLeftSide.removeChild(theLeftSide.firstChild);
}
while (theRightSide.firstChild) {
theRightSide.removeChild(theRightSide.firstChild);
}
for (i = 0; i < numberOfFaces; ++i) {
elem_img = document.createElement("img");
elem_img.src = "http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png";
elem_img.style.top = Math.floor(Math.random() * 401) + "px";
elem_img.style.left = Math.floor(Math.random() * 401) + "px";
theLeftSide.appendChild(elem_img);
}
leftSideImages = theLeftSide.cloneNode(true);
leftSideImages.removeChild(leftSideImages.lastChild);
theRightSide.appendChild(leftSideImages);
theLeftSide.lastChild.onclick = function nextLevel(event) {
event.stopPropagation();
numberOfFaces += 5;
generateFaces();
}
}
generateFaces();
theBody.onclick = function gameOver() {
alert("Game Over!");
theBody.onclick = null;
theLeftSide.lastChild.onclick = null;
}