ShareShortcuts

Snake Game

It a mini game fun 🤩

pooopv
Dupliquer « Snake Game »

Tu as créé quelque chose de nouveau à partir de ce raccourci ? Partage-le comme version dérivée : il devient un raccourci à toi, que tu gères, et les deux pages renvoient l’une vers l’autre pour que pooopv soit crédité.

  1. 1Obtenez le raccourci et modifiez-le dans l’app Raccourcis. Donnez-lui un nom bien à lui.
  2. 2Partage-le depuis l’app Raccourcis et copie le lien iCloud.
  3. 3Reviens ici, colle le lien et décris ce qui change, par exemple : « Ajout d’une étape qui utilise Apple Intelligence pour personnaliser le texte. »
Créer mon fork
Téléchargements
3K
Enregistré
1
Actions
3
Catégorie
Fun
Version
1.0
Langue
EN

It a mini game fun 🤩

Nouveautés

Version 1.0

First release

Historique des versions
1.0 3 août 2026

First release

Ce qu’il fait

3 actions
  1. Text
  2. Set Name
  3. Show Web Page

Afficher en tant que code
Bêta

Chaque action de ce raccourci écrite en Cherri, un langage de programmation pour Raccourcis. Idéal pour comprendre son fonctionnement.

#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()
Décompilé avec cherri 2.3.0 (GPL-2.0). Quelques corrections peuvent être nécessaires avant la compilation.

Notes et avis

Écrire un avis
–
sur 5
★★★★★
★★★★
★★★
★★
★
0 ratings

Aucun avis pour le moment. Sois le premier à partager ton avis !

Publicité

Plus de pooopv

Tout afficher

Ça pourrait aussi te plaire

Tout afficher
Publicité