-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
65 lines (49 loc) · 1.37 KB
/
script.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
var numberofface=5;
var score=0;
var leftside=document.getElementById("leftside");
var rightside=document.getElementById("rightside");
function generateFace() {
while(leftside.firstChild){
leftside.removeChild(leftside.firstChild);
}
while(rightside.firstChild){
rightside.removeChild(rightside.firstChild);
}
for (var i=0;i<numberofface;i++){
var img=document.createElement("img");
img.setAttribute("src","img.png");
img.style.width="100px";
img.style.position="absolute";
var rundnumberleft=Math.random()*380;
var rundnumbertop=Math.random()*380;
img.style.left=rundnumberleft+"px";
img.style.top=rundnumbertop+"px";
img.setAttribute("id",i);
leftside.appendChild(img);
}
cln=leftside.cloneNode("true");
cln.removeChild(cln.lastChild);
rightside.appendChild(cln);
event.stopPropagation();
leftside.lastChild.onclick=createClickHandler();
}
var createClickHandler = function(arg) {
return function load(){
numberofface+=5;
generateFace();
score=score+100;
var h2=document.getElementById("h2");
h2.innerHTML="Score: "+score;
}
}
function start() {
generateFace();
var theBody=document.getElementsByTagName('body')[0];
theBody.onclick=function gameover() {
alert("game over");
numberofface=5;
h2.innerHTML="Score:"
score=0;
generateFace();
}
}