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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>Snake Game - Mobile Friendly</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
margin: 0;
|
10 |
+
display: flex;
|
11 |
+
flex-direction: column;
|
12 |
+
justify-content: center;
|
13 |
+
align-items: center;
|
14 |
+
min-height: 100vh;
|
15 |
+
background: #1a1a1a;
|
16 |
+
font-family: 'Arial', sans-serif;
|
17 |
+
touch-action: none;
|
18 |
+
}
|
19 |
+
|
20 |
+
.game-container {
|
21 |
+
position: relative;
|
22 |
+
padding: 20px;
|
23 |
+
border-radius: 15px;
|
24 |
+
background: #2a2a2a;
|
25 |
+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
|
26 |
+
margin-bottom: 20px;
|
27 |
+
}
|
28 |
+
|
29 |
+
#gameCanvas {
|
30 |
+
border-radius: 10px;
|
31 |
+
background: #333;
|
32 |
+
}
|
33 |
+
|
34 |
+
.score {
|
35 |
+
position: absolute;
|
36 |
+
top: -40px;
|
37 |
+
left: 0;
|
38 |
+
color: #fff;
|
39 |
+
font-size: 20px;
|
40 |
+
font-weight: bold;
|
41 |
+
}
|
42 |
+
|
43 |
+
.controls {
|
44 |
+
display: none;
|
45 |
+
margin-top: 20px;
|
46 |
+
gap: 10px;
|
47 |
+
}
|
48 |
+
|
49 |
+
.mobile-controls {
|
50 |
+
display: grid;
|
51 |
+
grid-template-columns: repeat(3, 1fr);
|
52 |
+
gap: 10px;
|
53 |
+
margin-top: 20px;
|
54 |
+
}
|
55 |
+
|
56 |
+
.control-btn {
|
57 |
+
width: 60px;
|
58 |
+
height: 60px;
|
59 |
+
border: none;
|
60 |
+
border-radius: 50%;
|
61 |
+
background: #4CAF50;
|
62 |
+
color: white;
|
63 |
+
font-size: 24px;
|
64 |
+
cursor: pointer;
|
65 |
+
transition: all 0.2s ease;
|
66 |
+
touch-action: manipulation;
|
67 |
+
}
|
68 |
+
|
69 |
+
.control-btn:active {
|
70 |
+
transform: scale(0.9);
|
71 |
+
background: #45a049;
|
72 |
+
}
|
73 |
+
|
74 |
+
#up {
|
75 |
+
grid-column: 2;
|
76 |
+
}
|
77 |
+
|
78 |
+
#down {
|
79 |
+
grid-column: 2;
|
80 |
+
grid-row: 2;
|
81 |
+
}
|
82 |
+
|
83 |
+
#left {
|
84 |
+
grid-column: 1;
|
85 |
+
grid-row: 2;
|
86 |
+
}
|
87 |
+
|
88 |
+
#right {
|
89 |
+
grid-column: 3;
|
90 |
+
grid-row: 2;
|
91 |
+
}
|
92 |
+
|
93 |
+
#startBtn {
|
94 |
+
padding: 12px 30px;
|
95 |
+
font-size: 16px;
|
96 |
+
background: linear-gradient(135deg, #4CAF50, #45a049);
|
97 |
+
color: white;
|
98 |
+
border: none;
|
99 |
+
border-radius: 25px;
|
100 |
+
cursor: pointer;
|
101 |
+
transition: transform 0.3s ease;
|
102 |
+
box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
|
103 |
+
}
|
104 |
+
|
105 |
+
.game-over {
|
106 |
+
position: absolute;
|
107 |
+
top: 50%;
|
108 |
+
left: 50%;
|
109 |
+
transform: translate(-50%, -50%);
|
110 |
+
background: rgba(0, 0, 0, 0.9);
|
111 |
+
color: white;
|
112 |
+
padding: 20px 40px;
|
113 |
+
border-radius: 10px;
|
114 |
+
text-align: center;
|
115 |
+
display: none;
|
116 |
+
backdrop-filter: blur(5px);
|
117 |
+
}
|
118 |
+
|
119 |
+
@media (max-width: 600px) {
|
120 |
+
.mobile-controls {
|
121 |
+
display: grid;
|
122 |
+
}
|
123 |
+
}
|
124 |
+
.programmer-name {
|
125 |
+
position: fixed;
|
126 |
+
bottom: 20px;
|
127 |
+
left: 50%;
|
128 |
+
transform: translateX(-50%);
|
129 |
+
color: rgba(255, 255, 255, 0.8);
|
130 |
+
font-size: 18px;
|
131 |
+
font-family: 'Courier New', monospace;
|
132 |
+
text-transform: uppercase;
|
133 |
+
letter-spacing: 5px;
|
134 |
+
cursor: pointer;
|
135 |
+
transition: all 0.5s ease;
|
136 |
+
animation: float 3s ease-in-out infinite;
|
137 |
+
}
|
138 |
+
|
139 |
+
.programmer-name:hover {
|
140 |
+
color: #4CAF50;
|
141 |
+
letter-spacing: 8px;
|
142 |
+
text-shadow: 0 0 10px rgba(76, 175, 80, 0.8);
|
143 |
+
}
|
144 |
+
|
145 |
+
@keyframes float {
|
146 |
+
0%, 100% {
|
147 |
+
transform: translateX(-50%) translateY(0);
|
148 |
+
}
|
149 |
+
50% {
|
150 |
+
transform: translateX(-50%) translateY(-10px);
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
.name-effect {
|
155 |
+
position: fixed;
|
156 |
+
width: 20px;
|
157 |
+
height: 20px;
|
158 |
+
background: rgba(76, 175, 80, 0.5);
|
159 |
+
border-radius: 50%;
|
160 |
+
pointer-events: none;
|
161 |
+
animation: ripple 1s ease-out;
|
162 |
+
}
|
163 |
+
|
164 |
+
@keyframes ripple {
|
165 |
+
0% {
|
166 |
+
transform: scale(0);
|
167 |
+
opacity: 1;
|
168 |
+
}
|
169 |
+
100% {
|
170 |
+
transform: scale(2);
|
171 |
+
opacity: 0;
|
172 |
+
}
|
173 |
+
}
|
174 |
+
</style>
|
175 |
+
</head>
|
176 |
+
<body>
|
177 |
+
<div class="game-container">
|
178 |
+
<div class="score">Score: <span id="score">0</span></div>
|
179 |
+
<canvas id="gameCanvas" width="400" height="400"></canvas>
|
180 |
+
<div class="game-over" id="gameOver">
|
181 |
+
<h2>Game Over!</h2>
|
182 |
+
<p>Final Score: <span id="finalScore">0</span></p>
|
183 |
+
<button id="startBtn">Play Again</button>
|
184 |
+
</div>
|
185 |
+
</div>
|
186 |
+
|
187 |
+
<div class="mobile-controls">
|
188 |
+
<button class="control-btn" id="up">↑</button>
|
189 |
+
<button class="control-btn" id="left">←</button>
|
190 |
+
<button class="control-btn" id="right">→</button>
|
191 |
+
<button class="control-btn" id="down">↓</button>
|
192 |
+
</div>
|
193 |
+
|
194 |
+
<div class="programmer-name" id="programmerName">Ahmad Reza Anami</div>
|
195 |
+
|
196 |
+
<script>
|
197 |
+
const canvas = document.getElementById('gameCanvas');
|
198 |
+
const ctx = canvas.getContext('2d');
|
199 |
+
const scoreElement = document.getElementById('score');
|
200 |
+
const finalScoreElement = document.getElementById('finalScore');
|
201 |
+
const gameOverElement = document.getElementById('gameOver');
|
202 |
+
const startBtn = document.getElementById('startBtn');
|
203 |
+
const controlButtons = {
|
204 |
+
up: document.getElementById('up'),
|
205 |
+
down: document.getElementById('down'),
|
206 |
+
left: document.getElementById('left'),
|
207 |
+
right: document.getElementById('right')
|
208 |
+
};
|
209 |
+
|
210 |
+
const gridSize = 20;
|
211 |
+
const tileCount = canvas.width / gridSize;
|
212 |
+
let snake = [];
|
213 |
+
let food = {};
|
214 |
+
let goldenFood = null;
|
215 |
+
let dx = gridSize;
|
216 |
+
let dy = 0;
|
217 |
+
let score = 0;
|
218 |
+
let gameLoop;
|
219 |
+
let goldenFoodInterval;
|
220 |
+
let growth = 0;
|
221 |
+
let gameSpeed = 100;
|
222 |
+
|
223 |
+
function initGame() {
|
224 |
+
snake = [
|
225 |
+
{ x: 5 * gridSize, y: 5 * gridSize },
|
226 |
+
{ x: 4 * gridSize, y: 5 * gridSize }
|
227 |
+
];
|
228 |
+
spawnFood();
|
229 |
+
score = 0;
|
230 |
+
growth = 0;
|
231 |
+
goldenFood = null;
|
232 |
+
scoreElement.textContent = score;
|
233 |
+
dx = gridSize;
|
234 |
+
dy = 0;
|
235 |
+
gameSpeed = 100;
|
236 |
+
gameOverElement.style.display = 'none';
|
237 |
+
|
238 |
+
clearInterval(gameLoop);
|
239 |
+
clearInterval(goldenFoodInterval);
|
240 |
+
|
241 |
+
gameLoop = setInterval(update, gameSpeed);
|
242 |
+
goldenFoodInterval = setInterval(spawnGoldenFood, 5000);
|
243 |
+
}
|
244 |
+
|
245 |
+
function spawnFood() {
|
246 |
+
food = {
|
247 |
+
x: Math.floor(Math.random() * tileCount) * gridSize,
|
248 |
+
y: Math.floor(Math.random() * tileCount) * gridSize
|
249 |
+
};
|
250 |
+
if (snake.some(segment => segment.x === food.x && segment.y === food.y)) {
|
251 |
+
spawnFood();
|
252 |
+
}
|
253 |
+
}
|
254 |
+
|
255 |
+
function spawnGoldenFood() {
|
256 |
+
if (!goldenFood && Math.random() < 0.2) {
|
257 |
+
let newFood;
|
258 |
+
do {
|
259 |
+
newFood = {
|
260 |
+
x: Math.floor(Math.random() * tileCount) * gridSize,
|
261 |
+
y: Math.floor(Math.random() * tileCount) * gridSize
|
262 |
+
};
|
263 |
+
} while (snake.some(s => s.x === newFood.x && s.y === newFood.y) ||
|
264 |
+
(newFood.x === food.x && newFood.y === food.y));
|
265 |
+
|
266 |
+
goldenFood = newFood;
|
267 |
+
setTimeout(() => {
|
268 |
+
goldenFood = null;
|
269 |
+
}, 1000);
|
270 |
+
}
|
271 |
+
}
|
272 |
+
|
273 |
+
function update() {
|
274 |
+
let head = {
|
275 |
+
x: (snake[0].x + dx + canvas.width) % canvas.width,
|
276 |
+
y: (snake[0].y + dy + canvas.height) % canvas.height
|
277 |
+
};
|
278 |
+
|
279 |
+
if (snake.some(segment => segment.x === head.x && segment.y === head.y)) {
|
280 |
+
gameOver();
|
281 |
+
return;
|
282 |
+
}
|
283 |
+
|
284 |
+
snake.unshift(head);
|
285 |
+
|
286 |
+
if (head.x === food.x && head.y === food.y) {
|
287 |
+
score += 10;
|
288 |
+
growth += 1;
|
289 |
+
scoreElement.textContent = score;
|
290 |
+
spawnFood();
|
291 |
+
gameSpeed = Math.max(50, gameSpeed - 2);
|
292 |
+
clearInterval(gameLoop);
|
293 |
+
gameLoop = setInterval(update, gameSpeed);
|
294 |
+
} else if (goldenFood && head.x === goldenFood.x && head.y === goldenFood.y) {
|
295 |
+
score += 20;
|
296 |
+
growth += 2;
|
297 |
+
scoreElement.textContent = score;
|
298 |
+
goldenFood = null;
|
299 |
+
}
|
300 |
+
|
301 |
+
if (growth > 0) {
|
302 |
+
growth--;
|
303 |
+
} else {
|
304 |
+
snake.pop();
|
305 |
+
}
|
306 |
+
|
307 |
+
draw();
|
308 |
+
}
|
309 |
+
|
310 |
+
function draw() {
|
311 |
+
ctx.fillStyle = '#333';
|
312 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
313 |
+
|
314 |
+
snake.forEach((segment, index) => {
|
315 |
+
const gradient = ctx.createLinearGradient(
|
316 |
+
segment.x, segment.y,
|
317 |
+
segment.x + gridSize, segment.y + gridSize
|
318 |
+
);
|
319 |
+
gradient.addColorStop(0, index === 0 ? '#4CAF50' : '#45a049');
|
320 |
+
gradient.addColorStop(1, index === 0 ? '#45a049' : '#3d8b40');
|
321 |
+
|
322 |
+
ctx.fillStyle = gradient;
|
323 |
+
ctx.fillRect(segment.x + 1, segment.y + 1, gridSize - 2, gridSize - 2);
|
324 |
+
});
|
325 |
+
|
326 |
+
ctx.fillStyle = '#ff4444';
|
327 |
+
ctx.shadowColor = 'rgba(255, 68, 68, 0.5)';
|
328 |
+
ctx.shadowBlur = 10;
|
329 |
+
ctx.beginPath();
|
330 |
+
ctx.arc(food.x + gridSize/2, food.y + gridSize/2, gridSize/2 - 2, 0, Math.PI * 2);
|
331 |
+
ctx.fill();
|
332 |
+
|
333 |
+
if (goldenFood) {
|
334 |
+
ctx.fillStyle = '#FFD700';
|
335 |
+
ctx.shadowColor = 'rgba(255, 215, 0, 0.5)';
|
336 |
+
ctx.beginPath();
|
337 |
+
ctx.arc(goldenFood.x + gridSize/2, goldenFood.y + gridSize/2, gridSize/2 - 1, 0, Math.PI * 2);
|
338 |
+
ctx.fill();
|
339 |
+
}
|
340 |
+
|
341 |
+
ctx.shadowBlur = 0;
|
342 |
+
}
|
343 |
+
|
344 |
+
function gameOver() {
|
345 |
+
clearInterval(gameLoop);
|
346 |
+
clearInterval(goldenFoodInterval);
|
347 |
+
gameOverElement.style.display = 'block';
|
348 |
+
finalScoreElement.textContent = score;
|
349 |
+
}
|
350 |
+
|
351 |
+
// Control handlers
|
352 |
+
function handleDirectionChange(newDx, newDy) {
|
353 |
+
if ((dx === 0 && newDx !== 0) || (dy === 0 && newDy !== 0)) {
|
354 |
+
dx = newDx;
|
355 |
+
dy = newDy;
|
356 |
+
}
|
357 |
+
}
|
358 |
+
|
359 |
+
// Keyboard controls
|
360 |
+
document.addEventListener('keydown', (e) => {
|
361 |
+
switch(e.key) {
|
362 |
+
case 'ArrowUp': handleDirectionChange(0, -gridSize); break;
|
363 |
+
case 'ArrowDown': handleDirectionChange(0, gridSize); break;
|
364 |
+
case 'ArrowLeft': handleDirectionChange(-gridSize, 0); break;
|
365 |
+
case 'ArrowRight': handleDirectionChange(gridSize, 0); break;
|
366 |
+
}
|
367 |
+
});
|
368 |
+
|
369 |
+
// Mobile controls
|
370 |
+
Object.entries(controlButtons).forEach(([direction, button]) => {
|
371 |
+
const handlePress = (e) => {
|
372 |
+
e.preventDefault();
|
373 |
+
switch(direction) {
|
374 |
+
case 'up': handleDirectionChange(0, -gridSize); break;
|
375 |
+
case 'down': handleDirectionChange(0, gridSize); break;
|
376 |
+
case 'left': handleDirectionChange(-gridSize, 0); break;
|
377 |
+
case 'right': handleDirectionChange(gridSize, 0); break;
|
378 |
+
}
|
379 |
+
};
|
380 |
+
|
381 |
+
button.addEventListener('touchstart', handlePress);
|
382 |
+
button.addEventListener('mousedown', handlePress);
|
383 |
+
});
|
384 |
+
|
385 |
+
startBtn.addEventListener('click', initGame);
|
386 |
+
initGame();
|
387 |
+
|
388 |
+
// Add interactive name effect
|
389 |
+
const programmerName = document.getElementById('programmerName');
|
390 |
+
|
391 |
+
programmerName.addEventListener('click', (e) => {
|
392 |
+
// Create ripple effect
|
393 |
+
const ripple = document.createElement('div');
|
394 |
+
ripple.classList.add('name-effect');
|
395 |
+
ripple.style.left = `${e.clientX - 10}px`;
|
396 |
+
ripple.style.top = `${e.clientY - 10}px`;
|
397 |
+
document.body.appendChild(ripple);
|
398 |
+
|
399 |
+
// Remove ripple after animation
|
400 |
+
setTimeout(() => {
|
401 |
+
ripple.remove();
|
402 |
+
}, 1000);
|
403 |
+
|
404 |
+
// Change text temporarily
|
405 |
+
const originalText = programmerName.textContent;
|
406 |
+
programmerName.textContent = "❤️ Snake Master ❤️";
|
407 |
+
programmerName.style.color = '#ff4444';
|
408 |
+
programmerName.style.textShadow = '0 0 15px rgba(255, 68, 68, 0.8)';
|
409 |
+
|
410 |
+
setTimeout(() => {
|
411 |
+
programmerName.textContent = originalText;
|
412 |
+
programmerName.style.color = 'rgba(255, 255, 255, 0.8)';
|
413 |
+
programmerName.style.textShadow = 'none';
|
414 |
+
}, 2000);
|
415 |
+
});
|
416 |
+
|
417 |
+
// Add mouse move effect
|
418 |
+
document.addEventListener('mousemove', (e) => {
|
419 |
+
const x = e.clientX;
|
420 |
+
const y = e.clientY;
|
421 |
+
const rect = programmerName.getBoundingClientRect();
|
422 |
+
const dist = Math.sqrt(
|
423 |
+
Math.pow(x - (rect.left + rect.width / 2), 2) +
|
424 |
+
Math.pow(y - (rect.top + rect.height / 2), 2)
|
425 |
+
);
|
426 |
+
|
427 |
+
const maxDist = 200;
|
428 |
+
const scale = 1 + (1 - Math.min(dist / maxDist, 1)) * 0.2;
|
429 |
+
programmerName.style.transform = `translateX(-50%) scale(${scale})`;
|
430 |
+
});
|
431 |
+
</script>
|
432 |
+
</body>
|
433 |
+
</html>
|