-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemojiCatcherGame.html
More file actions
172 lines (142 loc) · 4.46 KB
/
emojiCatcherGame.html
File metadata and controls
172 lines (142 loc) · 4.46 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!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>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
height: 100vh;
font-family: sans-serif;
background: linear-gradient(rgb(201, 65, 65), rgb(141, 24, 24), rgb(83, 18, 18));
}
.scores-container {
display: flex;
justify-content: center;
align-items: center;
}
.total-score {
margin-right: 20px;
margin: 20px;
text-align: center;
background: white;
padding: 20px;
color: black;
box-shadow: inset 0px 0px 25px 2px black;
}
.time {
margin-right: 20px;
margin: 20px;
text-align: center;
background: white;
color: black;
padding: 20px;
box-shadow: inset 0px 0px 25px 2px black
}
.grid-container {
display: flex;
justify-content: center;
align-items: center;
}
.grid {
width: 90%;
height: 90%;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
background: rgb(43, 0, 0);
box-shadow: 0 3px 10px black;
margin-top: 2rem;
padding: 20px;
}
.square {
height: 150px;
width: 200px;
margin: 10px;
border: 1px solid;
box-shadow: 0 3px 10px rgb(0, 0, 0);
background: transparent;
}
/* Javascript */
.emoji {
background: url(images/emoji.png);
background-position: center;
/* mix-blend-mode: color-burn; */
background-size: cover;
cursor: pointer;
}
</style>
</head>
<body>
<div class="scores-container">
<div class="total-score">
<h2>Your Score:</h2>
<h2 id="score">0</h2>
</div>
<div class="time">
<h2>Time Left:</h2>
<h2 id="time-left">60</h2>
</div>
</div>
<div class="grid-container">
<div class="grid">
<div class=" square" id="1"></div>
<div class="square" id="2"></div>
<div class="square" id="3"></div>
<div class="square" id="4"></div>
<div class="square" id="5"></div>
<div class="square" id="6"></div>
<div class="square" id="7"></div>
<div class="square" id="8"></div>
<div class="square" id="9"></div>
<div class="square" id="10"></div>
</div>
</div>
<script>
const squares = document.querySelectorAll('.square'),
timeLeft = document.querySelector("#time-left"),
score = document.querySelector("#score");
let result = 0;
let hitPostion;
let currentTime = 60;
let timerId = null;
function randomSquare() {
squares.forEach(square => {
square.classList.remove("emoji")
})
let randomSquare = squares[Math.floor(Math.random() * 9) + 1]
randomSquare.classList.add("emoji")
hitPostion = randomSquare.id
}
squares.forEach(square => {
square.addEventListener("mousedown", () => {
if (square.id == hitPostion) {
result++
score.textContent = result;
hitPostion = null
}
})
})
function moveEmoji() {
timeId = setInterval(randomSquare, 500)
}
moveEmoji()
function countDown() {
currentTime--;
timeLeft.textContent = currentTime
if (currentTime == 0) {
clearInterval(countDownTimerId)
clearInterval(timeId)
alert(`Game Over! Your Final Scores Is ${result}`);
}
}
let countDownTimerId = setInterval(countDown, 1000)
</script>
</body>
</html>