-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
62 lines (58 loc) · 1.67 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Butterfly Catch Game</title>
<style>
body {
text-align: center;
font-family: Arial, sans-serif;
background-color: #f0f8ff;
overflow: hidden;
}
#game-container {
position: relative;
width: 100vw;
height: 100vh;
}
#butterfly {
position: absolute;
width: 80px;
height: 80px;
cursor: pointer;
}
#score {
font-size: 24px;
font-weight: bold;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Catch the Butterfly! 🦋</h1>
<p id="score">Score: 0</p>
<div id="game-container">
<img id="butterfly" src="butterfly.gif" alt="Butterfly">
</div>
<script>
let score = 0;
const butterfly = document.getElementById("butterfly");
const scoreDisplay = document.getElementById("score");
function moveButterfly() {
const maxX = window.innerWidth - 80;
const maxY = window.innerHeight - 80;
const randomX = Math.floor(Math.random() * maxX);
const randomY = Math.floor(Math.random() * maxY);
butterfly.style.left = `${randomX}px`;
butterfly.style.top = `${randomY}px`;
}
butterfly.addEventListener("click", () => {
score++;
scoreDisplay.textContent = `Score: ${score}`;
moveButterfly();
});
moveButterfly();
</script>
</body>
</html>