#70,450,654textInscription #64987129#64,987,129svgInscription #64987128#64,987,128svgInscription #64987127#64,987,127svgInscription #64987126#64,987,126svgInscription #64987125#64,987,125svgInscription #64987124#64,987,124svgInscription #64987123#64,987,123svgInscription #64987122#64,987,122svgInscription #64987121#64,987,121svgInscription #11365687#11,365,687webpInscription #11365686#11,365,686webpInscription #11365685#11,365,685webpInscription #11365683#11,365,683webpInscription #11365677#11,365,677webp<!DOCTYPE html> <html> <head> <title>Snake Game</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style> canvas { border: 1px solid black; } </style> </head> <body> <canvas id="canvas" width="400" height="400"></canvas> <script> const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); const cellSize = 10; let snake = [{x: 5, y: 5}]; let direction = "right"; let food = {x: 10, y: 10}; let score = 0; function drawSnake() { ctx.fillStyle = "green"; snake.forEach(function(cell) { ctx.fillRect(cell.x * cellSize, cell.y * cellSize, cellSize, cellSize); }); } function moveSnake() { let head = snake[0]; if (direction === "right") { snake.unshift({x: head.x + 1, y: head.y}); } else if (direction === "left") { snake.unshift({x: head.x - 1, y: head.y}); } else if (direction === "up") { snake.unshift({x: head.x, y: head.y - 1}); } else if (direction === "down") { snake.unshift({x: head.x, y: head.y + 1}); } if (snake[0].x === food.x && snake[0].y === food.y) { food = { x: Math.floor(Math.random() * (canvas.width / cellSize)), y: Math.floor(Math.random() * (canvas.height / cellSize)) }; score++; } else { snake.pop(); } } function drawFood() { ctx.fillStyle = "red"; ctx.fillRect(food.x * cellSize, food.y * cellSize, cellSize, cellSize); } function drawScore() { ctx.fillStyle = "black"; ctx.font = "20px Arial"; ctx.fillText(`Score: ${score}`, 10, canvas.height - 10); } function update() { ctx.clearRect(0, 0, canvas.width, canvas.height); drawSnake(); moveSnake(); drawFood(); drawScore(); } function handleKeyDown(event) { if (event.key === "ArrowRight" && direction !== "left") { direction = "right"; } else if (event.key === "ArrowLeft" && direction !== "right") { direction = "left"; } else if (event.key === "ArrowUp" && direction !== "down") { direction = "up"; } else if (event.key === "ArrowDown" && direction !== "up") { direction = "down"; } } setInterval(update, 100); document.addEventListener("keydown", handleKeyDown); </script> </body> </html> #636,725textInscription #634680#634,680html<!DOCTYPE html> <html> <head> <title>Snake Game</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style> canvas { border: 1px solid black; } </style> </head> <body> <canvas id="canvas" width="400" height="400"></canvas> <script> const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); const cellSize = 10; let snake = [{x: 5, y: 5}]; let direction = "right"; let food = {x: 10, y: 10}; let score = 0; function drawSnake() { ctx.fillStyle = "green"; snake.forEach(function(cell) { ctx.fillRect(cell.x * cellSize, cell.y * cellSize, cellSize, cellSize); }); } function moveSnake() { let head = snake[0]; if (direction === "right") { snake.unshift({x: head.x + 1, y: head.y}); } else if (direction === "left") { snake.unshift({x: head.x - 1, y: head.y}); } else if (direction === "up") { snake.unshift({x: head.x, y: head.y - 1}); } else if (direction === "down") { snake.unshift({x: head.x, y: head.y + 1}); } if (snake[0].x === food.x && snake[0].y === food.y) { food = { x: Math.floor(Math.random() * (canvas.width / cellSize)), y: Math.floor(Math.random() * (canvas.height / cellSize)) }; score++; } else { snake.pop(); } } function drawFood() { ctx.fillStyle = "red"; ctx.fillRect(food.x * cellSize, food.y * cellSize, cellSize, cellSize); } function drawScore() { ctx.fillStyle = "black"; ctx.font = "20px Arial"; ctx.fillText(`Score: ${score}`, 10, canvas.height - 10); } function update() { ctx.clearRect(0, 0, canvas.width, canvas.height); drawSnake(); moveSnake(); drawFood(); drawScore(); } function handleKeyDown(event) { if (event.key === "ArrowRight" && direction !== "left") { direction = "right"; } else if (event.key === "ArrowLeft" && direction !== "right") { direction = "left"; } else if (event.key === "ArrowUp" && direction !== "down") { direction = "up"; } else if (event.key === "ArrowDown" && direction !== "up") { direction = "down"; } } setInterval(update, 100); document.addEventListener("keydown", handleKeyDown); </script> </body> </html> #634,224text<!DOCTYPE html> <html> <head> <title>Snake Game</title> <style> canvas { border: 1px solid black; } </style> </head> <body> <canvas id="canvas" width="400" height="400"></canvas> <script> const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); const cellSize = 10; let snake = [{x: 5, y: 5}]; let direction = "right"; let food = {x: 10, y: 10}; let score = 0; function drawSnake() { ctx.fillStyle = "green"; snake.forEach(function(cell) { ctx.fillRect(cell.x * cellSize, cell.y * cellSize, cellSize, cellSize); }); } function moveSnake() { let head = snake[0]; if (direction === "right") { snake.unshift({x: head.x + 1, y: head.y}); } else if (direction === "left") { snake.unshift({x: head.x - 1, y: head.y}); } else if (direction === "up") { snake.unshift({x: head.x, y: head.y - 1}); } else if (direction === "down") { snake.unshift({x: head.x, y: head.y + 1}); } if (snake[0].x === food.x && snake[0].y === food.y) { food = { x: Math.floor(Math.random() * (canvas.width / cellSize)), y: Math.floor(Math.random() * (canvas.height / cellSize)) }; score++; } else { snake.pop(); } } function drawFood() { ctx.fillStyle = "red"; ctx.fillRect(food.x * cellSize, food.y * cellSize, cellSize, cellSize); } function drawScore() { ctx.fillStyle = "black"; ctx.font = "20px Arial"; ctx.fillText(`Score: ${score}`, 10, canvas.height - 10); } function update() { ctx.clearRect(0, 0, canvas.width, canvas.height); drawSnake(); moveSnake(); drawFood(); drawScore(); } function handleKeyDown(event) { if (event.key === "ArrowRight" && direction !== "left") { direction = "right"; } else if (event.key === "ArrowLeft" && direction !== "right") { direction = "left"; } else if (event.key === "ArrowUp" && direction !== "down") { direction = "up"; } else if (event.key === "ArrowDown" && direction !== "up") { direction = "down"; } } setInterval(update, 100); document.addEventListener("keydown", handleKeyDown); </script> </body> </html> #630,420textInscription #605464#605,464pngInscription #572948#572,948pngInscription #572945#572,945pngInscription #572588#572,588pngInscription #570582#570,582pngInscription #567695#567,695pngInscription #567694#567,694pngInscription #530044#530,044png^_^#528,447text