create-template-html-css 1.9.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +80 -0
- package/COMPONENTS-GALLERY.html +735 -747
- package/README.md +179 -2
- package/bin/cli.js +15 -3
- package/package.json +1 -1
- package/templates/blackjack/index.html +97 -0
- package/templates/blackjack/script.js +381 -0
- package/templates/blackjack/style.css +452 -0
- package/templates/breakout/index.html +56 -0
- package/templates/breakout/script.js +387 -0
- package/templates/breakout/style.css +239 -0
- package/templates/connect-four/index.html +78 -0
- package/templates/connect-four/script.js +413 -0
- package/templates/connect-four/style.css +426 -0
- package/templates/dice-game/index.html +99 -0
- package/templates/dice-game/script.js +291 -0
- package/templates/dice-game/style.css +403 -0
- package/templates/flappy-bird/index.html +47 -0
- package/templates/flappy-bird/script.js +394 -0
- package/templates/flappy-bird/style.css +243 -0
- package/templates/game-2048/index.html +59 -0
- package/templates/game-2048/script.js +269 -0
- package/templates/game-2048/style.css +281 -0
- package/templates/pong/index.html +90 -0
- package/templates/pong/script.js +364 -0
- package/templates/pong/style.css +371 -0
- package/templates/rock-paper-scissors/index.html +84 -0
- package/templates/rock-paper-scissors/script.js +199 -0
- package/templates/rock-paper-scissors/style.css +295 -0
- package/templates/simon-says/index.html +64 -0
- package/templates/simon-says/script.js +206 -0
- package/templates/simon-says/style.css +250 -0
- package/templates/slot-machine/index.html +112 -0
- package/templates/slot-machine/script.js +238 -0
- package/templates/slot-machine/style.css +464 -0
- package/templates/tetris/index.html +84 -0
- package/templates/tetris/script.js +447 -0
- package/templates/tetris/style.css +286 -0
- package/templates/whack-a-mole/index.html +85 -0
- package/templates/whack-a-mole/script.js +172 -0
- package/{demo-games/snake-game → templates/whack-a-mole}/style.css +114 -97
- package/PUBLISH-GUIDE.md +0 -112
- package/create-template-html-css-1.8.0.tgz +0 -0
- package/demo-games/guess-number/index.html +0 -71
- package/demo-games/guess-number/script.js +0 -216
- package/demo-games/guess-number/style.css +0 -337
- package/demo-games/memory-game/index.html +0 -50
- package/demo-games/memory-game/script.js +0 -216
- package/demo-games/memory-game/style.css +0 -288
- package/demo-games/snake-game/index.html +0 -61
- package/demo-games/snake-game/script.js +0 -360
- package/demo-games/tic-tac-toe/index.html +0 -57
- package/demo-games/tic-tac-toe/script.js +0 -156
- package/demo-games/tic-tac-toe/style.css +0 -244
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
* {
|
|
2
|
+
margin: 0;
|
|
3
|
+
padding: 0;
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
body {
|
|
8
|
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
9
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
10
|
+
min-height: 100vh;
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
align-items: center;
|
|
14
|
+
padding: 20px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.container {
|
|
18
|
+
background: white;
|
|
19
|
+
border-radius: 20px;
|
|
20
|
+
padding: 30px;
|
|
21
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
22
|
+
max-width: 900px;
|
|
23
|
+
width: 100%;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.header {
|
|
27
|
+
text-align: center;
|
|
28
|
+
margin-bottom: 25px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.header h1 {
|
|
32
|
+
color: #2d3748;
|
|
33
|
+
font-size: 2.5rem;
|
|
34
|
+
margin-bottom: 5px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.subtitle {
|
|
38
|
+
color: #718096;
|
|
39
|
+
font-size: 1.1rem;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.game-container {
|
|
43
|
+
display: flex;
|
|
44
|
+
gap: 20px;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
align-items: flex-start;
|
|
47
|
+
margin-bottom: 20px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.side-panel {
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
gap: 15px;
|
|
54
|
+
min-width: 180px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.info-card {
|
|
58
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
59
|
+
padding: 15px;
|
|
60
|
+
border-radius: 12px;
|
|
61
|
+
text-align: center;
|
|
62
|
+
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.info-card h3 {
|
|
66
|
+
color: rgba(255, 255, 255, 0.9);
|
|
67
|
+
font-size: 0.9rem;
|
|
68
|
+
margin-bottom: 8px;
|
|
69
|
+
font-weight: 600;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.score-value {
|
|
73
|
+
color: white;
|
|
74
|
+
font-size: 2rem;
|
|
75
|
+
font-weight: bold;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.next-piece {
|
|
79
|
+
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#nextCanvas {
|
|
83
|
+
display: block;
|
|
84
|
+
margin: 10px auto 0;
|
|
85
|
+
background: #1a202c;
|
|
86
|
+
border-radius: 8px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.game-board {
|
|
90
|
+
flex-shrink: 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#gameCanvas {
|
|
94
|
+
display: block;
|
|
95
|
+
border-radius: 10px;
|
|
96
|
+
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.controls {
|
|
100
|
+
display: flex;
|
|
101
|
+
gap: 15px;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
margin-bottom: 25px;
|
|
104
|
+
flex-wrap: wrap;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.btn {
|
|
108
|
+
padding: 12px 30px;
|
|
109
|
+
font-size: 1rem;
|
|
110
|
+
font-weight: 600;
|
|
111
|
+
border: none;
|
|
112
|
+
border-radius: 8px;
|
|
113
|
+
cursor: pointer;
|
|
114
|
+
transition: all 0.3s ease;
|
|
115
|
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
|
116
|
+
min-width: 120px;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.btn:hover:not(:disabled) {
|
|
120
|
+
transform: translateY(-2px);
|
|
121
|
+
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.btn:active:not(:disabled) {
|
|
125
|
+
transform: translateY(0);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.btn:disabled {
|
|
129
|
+
opacity: 0.5;
|
|
130
|
+
cursor: not-allowed;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.btn-primary {
|
|
134
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
135
|
+
color: white;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.btn-secondary {
|
|
139
|
+
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
|
140
|
+
color: white;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.btn-danger {
|
|
144
|
+
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
|
|
145
|
+
color: white;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.instructions {
|
|
149
|
+
background: #f7fafc;
|
|
150
|
+
padding: 20px;
|
|
151
|
+
border-radius: 10px;
|
|
152
|
+
border: 2px solid #e2e8f0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.instructions h3 {
|
|
156
|
+
color: #2d3748;
|
|
157
|
+
margin-bottom: 15px;
|
|
158
|
+
font-size: 1.1rem;
|
|
159
|
+
text-align: center;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.key-instructions {
|
|
163
|
+
display: flex;
|
|
164
|
+
flex-wrap: wrap;
|
|
165
|
+
gap: 15px;
|
|
166
|
+
justify-content: center;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.key-item {
|
|
170
|
+
display: flex;
|
|
171
|
+
flex-direction: column;
|
|
172
|
+
align-items: center;
|
|
173
|
+
gap: 8px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.key {
|
|
177
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
178
|
+
color: white;
|
|
179
|
+
padding: 10px 15px;
|
|
180
|
+
border-radius: 8px;
|
|
181
|
+
font-weight: bold;
|
|
182
|
+
font-size: 1.1rem;
|
|
183
|
+
min-width: 60px;
|
|
184
|
+
text-align: center;
|
|
185
|
+
box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.key-item span:last-child {
|
|
189
|
+
color: #4a5568;
|
|
190
|
+
font-size: 0.85rem;
|
|
191
|
+
font-weight: 600;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* Responsive */
|
|
195
|
+
@media (max-width: 768px) {
|
|
196
|
+
.container {
|
|
197
|
+
padding: 20px;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.header h1 {
|
|
201
|
+
font-size: 2rem;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.game-container {
|
|
205
|
+
flex-direction: column;
|
|
206
|
+
align-items: center;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.side-panel {
|
|
210
|
+
flex-direction: row;
|
|
211
|
+
flex-wrap: wrap;
|
|
212
|
+
justify-content: center;
|
|
213
|
+
width: 100%;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.info-card {
|
|
217
|
+
flex: 1;
|
|
218
|
+
min-width: 120px;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.next-piece {
|
|
222
|
+
flex: 0 0 100%;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
#gameCanvas {
|
|
226
|
+
max-width: 100%;
|
|
227
|
+
height: auto;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.controls {
|
|
231
|
+
gap: 10px;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.btn {
|
|
235
|
+
padding: 10px 20px;
|
|
236
|
+
min-width: 100px;
|
|
237
|
+
font-size: 0.9rem;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.instructions {
|
|
241
|
+
padding: 15px;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.key-instructions {
|
|
245
|
+
gap: 10px;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.key {
|
|
249
|
+
padding: 8px 12px;
|
|
250
|
+
min-width: 50px;
|
|
251
|
+
font-size: 1rem;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@media (max-width: 480px) {
|
|
256
|
+
.header h1 {
|
|
257
|
+
font-size: 1.5rem;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.subtitle {
|
|
261
|
+
font-size: 0.95rem;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.info-card {
|
|
265
|
+
padding: 12px;
|
|
266
|
+
min-width: 100px;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.score-value {
|
|
270
|
+
font-size: 1.5rem;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.key-instructions {
|
|
274
|
+
flex-direction: column;
|
|
275
|
+
align-items: stretch;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.key-item {
|
|
279
|
+
flex-direction: row;
|
|
280
|
+
justify-content: space-between;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.key {
|
|
284
|
+
min-width: 80px;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>{{name}} - Whack-a-Mole</title>
|
|
7
|
+
<link rel="stylesheet" href="style.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div class="container">
|
|
11
|
+
<div class="game-card">
|
|
12
|
+
<h1>🔨 Whack-a-Mole</h1>
|
|
13
|
+
|
|
14
|
+
<div class="game-stats">
|
|
15
|
+
<div class="stat">
|
|
16
|
+
<div class="stat-label">Score</div>
|
|
17
|
+
<div id="score" class="stat-value">0</div>
|
|
18
|
+
</div>
|
|
19
|
+
<div class="stat">
|
|
20
|
+
<div class="stat-label">Time</div>
|
|
21
|
+
<div id="timer" class="stat-value">30</div>
|
|
22
|
+
</div>
|
|
23
|
+
<div class="stat">
|
|
24
|
+
<div class="stat-label">High Score</div>
|
|
25
|
+
<div id="highScore" class="stat-value">0</div>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<div class="difficulty-selector">
|
|
30
|
+
<label>Difficulty:</label>
|
|
31
|
+
<select id="difficulty">
|
|
32
|
+
<option value="easy">Easy</option>
|
|
33
|
+
<option value="medium" selected>Medium</option>
|
|
34
|
+
<option value="hard">Hard</option>
|
|
35
|
+
</select>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div class="game-board" id="gameBoard">
|
|
39
|
+
<div class="hole" data-hole="0">
|
|
40
|
+
<div class="mole">🐹</div>
|
|
41
|
+
</div>
|
|
42
|
+
<div class="hole" data-hole="1">
|
|
43
|
+
<div class="mole">🐹</div>
|
|
44
|
+
</div>
|
|
45
|
+
<div class="hole" data-hole="2">
|
|
46
|
+
<div class="mole">🐹</div>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="hole" data-hole="3">
|
|
49
|
+
<div class="mole">🐹</div>
|
|
50
|
+
</div>
|
|
51
|
+
<div class="hole" data-hole="4">
|
|
52
|
+
<div class="mole">🐹</div>
|
|
53
|
+
</div>
|
|
54
|
+
<div class="hole" data-hole="5">
|
|
55
|
+
<div class="mole">🐹</div>
|
|
56
|
+
</div>
|
|
57
|
+
<div class="hole" data-hole="6">
|
|
58
|
+
<div class="mole">🐹</div>
|
|
59
|
+
</div>
|
|
60
|
+
<div class="hole" data-hole="7">
|
|
61
|
+
<div class="mole">🐹</div>
|
|
62
|
+
</div>
|
|
63
|
+
<div class="hole" data-hole="8">
|
|
64
|
+
<div class="mole">🐹</div>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<div class="message" id="message"></div>
|
|
69
|
+
|
|
70
|
+
<div class="button-group">
|
|
71
|
+
<button id="startBtn" class="btn btn-success">Start Game</button>
|
|
72
|
+
<button id="pauseBtn" class="btn btn-warning" disabled>Pause</button>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<div class="instructions">
|
|
76
|
+
<h3>How to Play:</h3>
|
|
77
|
+
<p>🔨 Click on the moles as they pop up!</p>
|
|
78
|
+
<p>⏱️ You have 30 seconds to score as many points as possible</p>
|
|
79
|
+
<p>🎯 Each hit = +1 point</p>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
<script src="script.js"></script>
|
|
84
|
+
</body>
|
|
85
|
+
</html>
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// Whack-a-Mole Game Logic
|
|
2
|
+
|
|
3
|
+
const holes = document.querySelectorAll('.hole');
|
|
4
|
+
const moles = document.querySelectorAll('.mole');
|
|
5
|
+
const scoreDisplay = document.getElementById('score');
|
|
6
|
+
const timerDisplay = document.getElementById('timer');
|
|
7
|
+
const highScoreDisplay = document.getElementById('highScore');
|
|
8
|
+
const startBtn = document.getElementById('startBtn');
|
|
9
|
+
const pauseBtn = document.getElementById('pauseBtn');
|
|
10
|
+
const messageDisplay = document.getElementById('message');
|
|
11
|
+
const difficultySelect = document.getElementById('difficulty');
|
|
12
|
+
|
|
13
|
+
let score = 0;
|
|
14
|
+
let timeLeft = 30;
|
|
15
|
+
let highScore = localStorage.getItem('whackHighScore') || 0;
|
|
16
|
+
let gameInterval = null;
|
|
17
|
+
let moleInterval = null;
|
|
18
|
+
let isPaused = false;
|
|
19
|
+
let isGameActive = false;
|
|
20
|
+
|
|
21
|
+
// Difficulty settings
|
|
22
|
+
const difficulties = {
|
|
23
|
+
easy: { minTime: 800, maxTime: 1500 },
|
|
24
|
+
medium: { minTime: 500, maxTime: 1200 },
|
|
25
|
+
hard: { minTime: 300, maxTime: 800 }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Initialize
|
|
29
|
+
highScoreDisplay.textContent = highScore;
|
|
30
|
+
|
|
31
|
+
// Start game
|
|
32
|
+
function startGame() {
|
|
33
|
+
score = 0;
|
|
34
|
+
timeLeft = 30;
|
|
35
|
+
isPaused = false;
|
|
36
|
+
isGameActive = true;
|
|
37
|
+
|
|
38
|
+
scoreDisplay.textContent = score;
|
|
39
|
+
timerDisplay.textContent = timeLeft;
|
|
40
|
+
messageDisplay.textContent = '';
|
|
41
|
+
|
|
42
|
+
startBtn.disabled = true;
|
|
43
|
+
pauseBtn.disabled = false;
|
|
44
|
+
difficultySelect.disabled = true;
|
|
45
|
+
|
|
46
|
+
// Hide all moles
|
|
47
|
+
moles.forEach(mole => mole.classList.remove('up', 'whacked'));
|
|
48
|
+
|
|
49
|
+
// Start timer
|
|
50
|
+
gameInterval = setInterval(() => {
|
|
51
|
+
if (!isPaused) {
|
|
52
|
+
timeLeft--;
|
|
53
|
+
timerDisplay.textContent = timeLeft;
|
|
54
|
+
|
|
55
|
+
if (timeLeft <= 0) {
|
|
56
|
+
endGame();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}, 1000);
|
|
60
|
+
|
|
61
|
+
// Start spawning moles
|
|
62
|
+
spawnMole();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Spawn mole
|
|
66
|
+
function spawnMole() {
|
|
67
|
+
if (!isGameActive) return;
|
|
68
|
+
|
|
69
|
+
const difficulty = difficultySelect.value;
|
|
70
|
+
const { minTime, maxTime } = difficulties[difficulty];
|
|
71
|
+
|
|
72
|
+
// Random hole
|
|
73
|
+
const randomHole = Math.floor(Math.random() * holes.length);
|
|
74
|
+
const mole = moles[randomHole];
|
|
75
|
+
|
|
76
|
+
// Check if already up
|
|
77
|
+
if (mole.classList.contains('up')) {
|
|
78
|
+
spawnMole();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Show mole
|
|
83
|
+
mole.classList.add('up');
|
|
84
|
+
|
|
85
|
+
// Random time to stay up
|
|
86
|
+
const upTime = Math.random() * (maxTime - minTime) + minTime;
|
|
87
|
+
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
if (mole.classList.contains('up') && !mole.classList.contains('whacked')) {
|
|
90
|
+
mole.classList.remove('up');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Spawn next mole
|
|
94
|
+
if (isGameActive && !isPaused) {
|
|
95
|
+
const spawnDelay = Math.random() * 300 + 200;
|
|
96
|
+
setTimeout(spawnMole, spawnDelay);
|
|
97
|
+
}
|
|
98
|
+
}, upTime);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Whack mole
|
|
102
|
+
function whack(e) {
|
|
103
|
+
if (!isGameActive || isPaused) return;
|
|
104
|
+
|
|
105
|
+
const mole = e.target;
|
|
106
|
+
|
|
107
|
+
if (mole.classList.contains('up') && !mole.classList.contains('whacked')) {
|
|
108
|
+
mole.classList.add('whacked');
|
|
109
|
+
score++;
|
|
110
|
+
scoreDisplay.textContent = score;
|
|
111
|
+
|
|
112
|
+
// Shake animation
|
|
113
|
+
mole.style.animation = 'shake 0.3s';
|
|
114
|
+
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
mole.classList.remove('up', 'whacked');
|
|
117
|
+
mole.style.animation = '';
|
|
118
|
+
}, 300);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Pause game
|
|
123
|
+
function pauseGame() {
|
|
124
|
+
isPaused = !isPaused;
|
|
125
|
+
|
|
126
|
+
if (isPaused) {
|
|
127
|
+
pauseBtn.textContent = 'Resume';
|
|
128
|
+
messageDisplay.textContent = 'Game Paused';
|
|
129
|
+
} else {
|
|
130
|
+
pauseBtn.textContent = 'Pause';
|
|
131
|
+
messageDisplay.textContent = '';
|
|
132
|
+
spawnMole();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// End game
|
|
137
|
+
function endGame() {
|
|
138
|
+
clearInterval(gameInterval);
|
|
139
|
+
isGameActive = false;
|
|
140
|
+
|
|
141
|
+
// Hide all moles
|
|
142
|
+
moles.forEach(mole => mole.classList.remove('up', 'whacked'));
|
|
143
|
+
|
|
144
|
+
startBtn.disabled = false;
|
|
145
|
+
pauseBtn.disabled = true;
|
|
146
|
+
pauseBtn.textContent = 'Pause';
|
|
147
|
+
difficultySelect.disabled = false;
|
|
148
|
+
|
|
149
|
+
// Update high score
|
|
150
|
+
if (score > highScore) {
|
|
151
|
+
highScore = score;
|
|
152
|
+
localStorage.setItem('whackHighScore', highScore);
|
|
153
|
+
highScoreDisplay.textContent = highScore;
|
|
154
|
+
messageDisplay.textContent = `🎉 New High Score: ${score}!`;
|
|
155
|
+
} else {
|
|
156
|
+
messageDisplay.textContent = `Game Over! Final Score: ${score}`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
messageDisplay.classList.add('show');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Event listeners
|
|
163
|
+
moles.forEach(mole => mole.addEventListener('click', whack));
|
|
164
|
+
startBtn.addEventListener('click', startGame);
|
|
165
|
+
pauseBtn.addEventListener('click', pauseGame);
|
|
166
|
+
|
|
167
|
+
// Prevent text selection on double click
|
|
168
|
+
document.addEventListener('selectstart', (e) => {
|
|
169
|
+
if (isGameActive) {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
}
|
|
172
|
+
});
|