-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainjs.html
56 lines (53 loc) · 1.44 KB
/
mainjs.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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<link rel="stylesheet" href ="style.css">
<meta charset="utf-8">
<title>Evader</title>
</head>
<body>
<script>
var counter = 1;
function myMove() {
moves = 0;
var myDiv = document.getElementById("evader");
xpos = parseInt(getComputedStyle(myDiv).getPropertyValue("left").match(/\d+/));
ypos = parseInt(getComputedStyle(myDiv).getPropertyValue("top").match(/\d+/));
if (xpos != 8 && xpos != 208) {
return;
}
if (ypos != 8 && ypos != 208) {
return;
}
var id = setInterval(frame, 5);
function frame() {
if (moves == 200) {
clearInterval(id);
} else {
if (counter <= 2) {
xpos += ((counter + 1) % 2);
ypos -= (counter % 2);
} else {
xpos -= ((counter + 1) % 2);
ypos += (counter % 2);
}
myDiv.style.left = xpos + 'px';
myDiv.style.top = ypos + 'px';
moves++;
}
}
if (counter < 4) {
counter++;
} else {
counter = 1;
}
}
</script>
<div id="evader">
<p>I am the Evader</p>
</div>
<div id="clicker">
<button onclick='myMove()'>Move the Evader</button>
</div>
</body>
</html>