-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmosquito_game.html
More file actions
76 lines (74 loc) · 1.98 KB
/
Copy pathmosquito_game.html
File metadata and controls
76 lines (74 loc) · 1.98 KB
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
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.playground {
width: 450px;
height: 450px;
display: flex;
justify-content: left;
/* align-items: center; */
background-color: #f0f0f0;
margin: 0 auto;
}
.mosquito {
position: relative;
}
</style>
</head>
<body>
<!-- <h1>Welcome to the Mosquito Game!</h1>
<p>Click the button below to start the game.</p>
<button id="start-button">Start Game</button> -->
<!-- <h1>Trades</h1> -->
<div class="playground">
<img
src="./Mosquito.png"
class="mosquito"
id="mosquito"
onclick="hitMosquito()"
width="30"
height="30"
alt="Mosquito"
/>
</div>
<div class="controle">
<button onclick="start()">Start</button>
<h3><span>Total</span> <span class="totalHits">0</span></h3>
</div>
<script>
let totalHits = 0;
let total = document.querySelector(".totalHits");
let isGameStarted = false;
function start() {
totalHits = 0;
isGameStarted = true;
let mosquito = document.getElementById("mosquito");
let time = setInterval(() => {
let i = Math.floor(Math.random() * 400);
let j = Math.floor(Math.random() * 400);
mosquito.style.top = i + "px";
mosquito.style.left = j + "px";
console.log(i, j);
}, 1000);
setTimeout(() => {
clearInterval(time);
isGameStarted = false;
// totalHits = 0;
console.log("Game Over");
}, 15000);
}
function hitMosquito() {
if (isGameStarted) {
totalHits++;
total.innerHTML = totalHits;
console.log(totalHits, "total hits");
}
// start();
}
</script>
</body>
</html>