Scan med din iPhone for at installere
It a mini game fun 🤩
Nyheder
Version 1.0
First release
Hvad den gør
3 handlinger-
Text
-
Set Name
-
Show Web Page
Vis som kode
Alle genvejens handlinger skrevet ud i Cherri, et programmeringssprog til genveje. Perfekt til at lære, hvordan den virker.
#include 'actions/web'
#define color green
#define glyph snake
const Text = "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\\"UTF-8\\">\n <meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\\">\n <title>Snake Game</title>\n <style>\n * { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; }\n body { background-color: #111; color: #fff; font-family: -apple-system, sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; overflow: hidden; }\n #gm-score { font-size: 24px; margin-bottom: 10px; font-weight: bold; }\n #canvas-container { position: relative; border: 4px solid #333; border-radius: 10px; background-color: #000; }\n canvas { display: block; border-radius: 6px; }\n #overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.75); display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 6px; }\n .btn { background-color: #4caf50; color: white; border: none; padding: 12px 24px; font-size: 18px; border-radius: 25px; cursor: pointer; margin-top: 15px; font-weight: bold; }\n .btn:active { transform: scale(0.95); }\n .controls { display: grid; grid-template-columns: repeat(3, 70px); grid-gap: 10px; margin-top: 20px; }\n .ctrl-btn { width: 70px; height: 70px; background: #222; border: 2px solid #444; border-radius: 50%; color: #fff; font-size: 24px; font-weight: bold; display: flex; align-items: center; justify-content: center; cursor: pointer; }\n .ctrl-btn:active { background: #333; }\n .blank { visibility: hidden; }\n </style>\n</head>\n<body>\n\n <div id=\\"gm-score\\">Score: 0</div>\n <div id=\\"canvas-container\\">\n <canvas id=\\"gmCanvas\\" width=\\"300\\" height=\\"300\\"></canvas>\n <div id=\\"overlay\\">\n <h2 id=\\"msg\\">Snake Game</h2>\n <button class=\\"btn\\" id=\\"startBtn\\">Play</button>\n </div>\n </div>\n\n <div class=\\"controls\\">\n <div class=\\"blank\\"></div>\n <div class=\\"ctrl-btn\\" id=\\"upBtn\\">▲</div>\n <div class=\\"blank\\"></div>\n <div class=\\"ctrl-btn\\" id=\\"leftBtn\\">◀</div>\n <div class=\\"ctrl-btn\\" id=\\"downBtn\\">▼</div>\n <div class=\\"ctrl-btn\\" id=\\"rightBtn\\">▶</div>\n </div>\n</body>\n<script>\n const canvas = document.getElementById('gmCanvas');\n const ctx = canvas.getContext('2d');\n const scoreDiv = document.getElementById('gm-score');\n const overlay = document.getElementById('overlay');\n const msg = document.getElementById('msg');\n const startBtn = document.getElementById('startBtn');\n\n const gridSize = 15;\n const tileCount = canvas.width / gridSize;\n let snake = [];\n let food = {x: 0, y: 0};\n let dx = gridSize, dy = 0;\n let nextDx = gridSize, nextDy = 0;\n let score = 0;\n let gameLoopId = null;\n let isGameOver = false;\n\n function startGame() {\n overlay.style.display = 'none';\n snake = [\n {x: gridSize * 5, y: gridSize * 5},\n {x: gridSize * 4, y: gridSize * 5},\n {x: gridSize * 3, y: gridSize * 5}\n ];\n dx = gridSize; dy = 0;\n nextDx = gridSize; nextDy = 0;\n score = 0;\n scoreDiv.innerHTML = 'Score: 0';\n isGameOver = false;\n spawnFood();\n if (gameLoopId) clearInterval(gameLoopId);\n gameLoopId = setInterval(update, 150);\n }\n\n function spawnFood() {\n food.x = Math.floor(Math.random() * tileCount) * gridSize;\n food.y = Math.floor(Math.random() * tileCount) * gridSize;\n for (let i = 0; i < snake.length; i++) {\n if (snake[i].x === food.x && snake[i].y === food.y) spawnFood();\n }\n }\n\n function update() {\n if (isGameOver) return;\n dx = nextDx; dy = nextDy;\n \n // FIXED LINE: Now correctly grabs the head position from index 0\n const head = {x: snake[0].x + dx, y: snake[0].y + dy};\n\n if (head.x < 0 || head.x >= canvas.width || head.y < 0 || head.y >= canvas.height) return endGame();\n for (let i = 0; i < snake.length; i++) {\n if (snake[i].x === head.x && snake[i].y === head.y) return endGame();\n }\n\n snake.unshift(head);\n if (head.x === food.x && head.y === food.y) {\n score++;\n scoreDiv.innerHTML = 'Score: ' + score;\n spawnFood();\n } else {\n snake.pop();\n }\n\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n ctx.fillStyle = '#f44336';\n ctx.fillRect(food.x, food.y, gridSize - 2, gridSize - 2);\n ctx.fillStyle = '#4CAF50';\n for (let i = 0; i < snake.length; i++) {\n ctx.fillRect(snake[i].x, snake[i].y, gridSize - 2, gridSize - 2);\n }\n }\n\n function endGame() {\n isGameOver = true;\n clearInterval(gameLoopId);\n msg.innerHTML = 'Game Over!';\n startBtn.innerHTML = 'Try Again';\n overlay.style.display = 'flex';\n }\n\n function changeDirection(dir) {\n if (dir === 'UP' && dy === 0) { nextDx = 0; nextDy = -gridSize; }\n if (dir === 'DOWN' && dy === 0) { nextDx = 0; nextDy = gridSize; }\n if (dir === 'LEFT' && dx === 0) { nextDx = -gridSize; nextDy = 0; }\n if (dir === 'RIGHT' && dx === 0) { nextDx = gridSize; nextDy = 0; }\n }\n\n document.getElementById('upBtn').addEventListener('touchstart', (e) => { e.preventDefault(); changeDirection('UP'); });\n document.getElementById('downBtn').addEventListener('touchstart', (e) => { e.preventDefault(); changeDirection('DOWN'); });\n document.getElementById('leftBtn').addEventListener('touchstart', (e) => { e.preventDefault(); changeDirection('LEFT'); });\n document.getElementById('rightBtn').addEventListener('touchstart', (e) => { e.preventDefault(); changeDirection('RIGHT'); });\n \n document.addEventListener('keydown', (e) => {\n if (e.key === 'ArrowUp') changeDirection('UP');\n if (e.key === 'ArrowDown') changeDirection('DOWN');\n if (e.key === 'ArrowLeft') changeDirection('LEFT');\n if (e.key === 'ArrowRight') changeDirection('RIGHT');\n });\n\n startBtn.addEventListener('click', startGame);\n startBtn.addEventListener('touchstart', (e) => { e.preventDefault(); startGame(); });\n</script>\n</html>\n"
setName(Text, "Snake.html")
showWebpage()
Dekompileret med cherri 2.3.0 (GPL-2.0). Kan kræve små rettelser, før den kan kompileres.
Bedømmelser og anmeldelser
Skriv en anmeldelse–
ud af 5
★★★★★
★★★★
★★★
★★
★
0 ratings
Ingen anmeldelser endnu. Vær den første!
Annonce
Mere fra pooopv
Du vil måske også kunne lide
Annonce