| Server IP : 89.108.64.180 / Your IP : 216.73.217.117 Web Server : Apache/2.4.41 (Ubuntu) System : Linux 89-108-64-180.cloudvps.regruhosting.ru 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-root ( 1010) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/milasha.online/ |
Upload File : |
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Змейка</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
font-family: 'Arial', sans-serif;
color: white;
overflow: hidden;
}
.game-container {
position: relative;
margin-bottom: 30px;
}
#gameCanvas {
background: #0d1b2a;
border: 4px solid #415a77;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.game-info {
display: flex;
justify-content: space-between;
width: 500px;
margin-bottom: 15px;
font-size: 20px;
font-weight: bold;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.message {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0, 0, 0, 0.85);
padding: 20px 40px;
border-radius: 15px;
text-align: center;
font-size: 28px;
font-weight: bold;
border: 3px solid #ff6b6b;
display: none;
z-index: 10;
}
.controls {
margin-top: 20px;
text-align: center;
font-size: 16px;
color: #e0e1dd;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.footer {
margin-top: 30px;
text-align: center;
font-size: 24px;
font-weight: bold;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
animation: pulse 2s infinite;
}
.copyright {
margin-top: 15px;
font-size: 14px;
color: #a9a9a9;
text-shadow: none;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.highlight {
color: #ff6b6b;
text-shadow: 0 0 10px #ff6b6b;
}
</style>
</head>
<body>
<div class="game-info">
<div>Счёт: <span id="score">0</span></div>
<div>Рекорд: <span id="highScore">0</span></div>
</div>
<div class="game-container">
<canvas id="gameCanvas" width="500" height="500"></canvas>
<div id="gameOverMessage" class="message">Игра окончена!<br>Нажмите Пробел для новой игры<br>ради Милаши..</div>
</div>
<div class="controls">
Управление: Стрелки или WASD
</div>
<div class="footer">
Арнольд Смолькин ради Милаши<span class="highlight">!!!!!!!!!!!!!!!!!!!!!!!!</span>
</div>
<script>
// Игровые переменные
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const scoreElement = document.getElementById('score');
const highScoreElement = document.getElementById('highScore');
const gameOverMessage = document.getElementById('gameOverMessage');
// Размеры
const gridSize = 20;
const gridWidth = canvas.width / gridSize;
const gridHeight = canvas.height / gridSize;
// Игровое состояние
let snake = [];
let food = {};
let direction = 'right';
let nextDirection = 'right';
let score = 0;
let highScore = localStorage.getItem('snakeHighScore') || 0;
let gameSpeed = 120;
let gameRunning = false;
let gameLoop;
// Инициализация игры
function initGame() {
// Начальная позиция змейки
snake = [
{x: 10, y: 10},
{x: 9, y: 10},
{x: 8, y: 10}
];
generateFood();
score = 0;
direction = 'right';
nextDirection = 'right';
gameRunning = true;
scoreElement.textContent = score;
highScoreElement.textContent = highScore;
gameOverMessage.style.display = 'none';
if (gameLoop) {
clearInterval(gameLoop);
}
gameLoop = setInterval(update, gameSpeed);
}
// Генерация еды
function generateFood() {
food = {
x: Math.floor(Math.random() * gridWidth),
y: Math.floor(Math.random() * gridHeight)
};
// Убедиться, что еда не появляется на змейке
for (let segment of snake) {
if (segment.x === food.x && segment.y === food.y) {
return generateFood();
}
}
}
// Обновление игры
function update() {
if (!gameRunning) return;
direction = nextDirection;
// Создаем новую голову
const head = {...snake[0]};
switch (direction) {
case 'up': head.y--; break;
case 'down': head.y++; break;
case 'left': head.x--; break;
case 'right': head.x++; break;
}
// Проверка столкновения со стенами
if (head.x < 0 || head.x >= gridWidth || head.y < 0 || head.y >= gridHeight) {
gameOver();
return;
}
// Проверка столкновения с самой собой
for (let i = 0; i < snake.length; i++) {
if (snake[i].x === head.x && snake[i].y === head.y) {
gameOver();
return;
}
}
// Добавляем новую голову
snake.unshift(head);
// Проверка поедания еды
if (head.x === food.x && head.y === food.y) {
score += 10;
scoreElement.textContent = score;
generateFood();
// Увеличиваем скорость каждые 50 очков
if (score % 50 === 0 && gameSpeed > 60) {
gameSpeed -= 10;
clearInterval(gameLoop);
gameLoop = setInterval(update, gameSpeed);
}
} else {
// Удаляем хвост если не съели еду
snake.pop();
}
draw();
}
// Отрисовка
function draw() {
// Очистка канваса
ctx.fillStyle = '#0d1b2a';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Отрисовка сетки
ctx.strokeStyle = '#1b263b';
ctx.lineWidth = 0.5;
for (let x = 0; x < canvas.width; x += gridSize) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, canvas.height);
ctx.stroke();
}
for (let y = 0; y < canvas.height; y += gridSize) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(canvas.width, y);
ctx.stroke();
}
// Отрисовка змейки
snake.forEach((segment, index) => {
if (index === 0) {
// Голова змейки
ctx.fillStyle = '#4ade80';
} else {
// Тело змейки
ctx.fillStyle = '#22c55e';
}
ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);
// Добавляем границу
ctx.strokeStyle = '#166534';
ctx.lineWidth = 2;
ctx.strokeRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);
});
// Отрисовка еды
ctx.fillStyle = '#ef4444';
ctx.beginPath();
ctx.arc(
food.x * gridSize + gridSize/2,
food.y * gridSize + gridSize/2,
gridSize/2 - 2,
0,
Math.PI * 2
);
ctx.fill();
// Добавляем блеск еде
ctx.fillStyle = '#fecaca';
ctx.beginPath();
ctx.arc(
food.x * gridSize + gridSize/3,
food.y * gridSize + gridSize/3,
gridSize/6,
0,
Math.PI * 2
);
ctx.fill();
}
// Конец игры
function gameOver() {
gameRunning = false;
clearInterval(gameLoop);
if (score > highScore) {
highScore = score;
localStorage.setItem('snakeHighScore', highScore);
highScoreElement.textContent = highScore;
}
gameOverMessage.style.display = 'block';
}
// Обработка клавиш
document.addEventListener('keydown', (e) => {
switch (e.key) {
case 'ArrowUp':
case 'w':
case 'W':
if (direction !== 'down') nextDirection = 'up';
break;
case 'ArrowDown':
case 's':
case 'S':
if (direction !== 'up') nextDirection = 'down';
break;
case 'ArrowLeft':
case 'a':
case 'A':
if (direction !== 'right') nextDirection = 'left';
break;
case 'ArrowRight':
case 'd':
case 'D':
if (direction !== 'left') nextDirection = 'right';
break;
case ' ':
if (!gameRunning) initGame();
break;
}
});
// Начало игры
highScoreElement.textContent = highScore;
initGame();
</script>
</body>
</html>