commit e583146b05c18a9293e5ea10ec3e792a7450aacd
Author: ffff:82.167.4.246 <ffff:82.167.4.246@snakescroll.scroll.pub> Date: 2024-12-28 18:33:35 +0000 Subject: updated script.js diff --git a/script.js b/script.js index 5e95ddd..d53b944 100644 --- a/script.js +++ b/script.js @@ -92,7 +92,7 @@ function placeFood() { function startGame() { if (gameRunning) return; snake = [{ x: 10, y: 10 }]; - direction = { x: 0, y: 0 }; // Initial direction: no movement + direction = { x: 1, y: 0 }; // Start moving right score = 0; placeFood(); gameRunning = true;
commit b8b22e82c9b6384a1b01bfb568396b29e53819d3
Author: ffff:82.167.4.246 <ffff:82.167.4.246@snakescroll.scroll.pub> Date: 2024-12-28 11:12:05 +0000 Subject: updated script.js diff --git a/script.js b/script.js index 0a241f0..5e95ddd 100644 --- a/script.js +++ b/script.js @@ -110,7 +110,7 @@ function resetGame() { window.addEventListener("keydown", (e) => { if (!gameRunning) return; - + console.log(e.key); switch (e.key) { case "ArrowUp": if (direction.y === 0) direction = { x: 0, y: -1 };
commit 16129db8a5f1c0a0795b918c0c61ac7fec1ce189
Author: ffff:82.167.4.246 <ffff:82.167.4.246@snakescroll.scroll.pub> Date: 2024-12-28 11:09:02 +0000 Subject: updated script.js diff --git a/script.js b/script.js index d2fb82c..0a241f0 100644 --- a/script.js +++ b/script.js @@ -12,6 +12,7 @@ let food = { x: 5, y: 5 }; let direction = { x: 0, y: 0 }; let score = 0; let gameRunning = false; +let gameInterval; function drawGame() { if (!gameRunning) return; @@ -35,6 +36,13 @@ function drawGame() { ctx.fillStyle = "#FF5252"; ctx.fillRect(food.x * gridSize, food.y * gridSize, gridSize, gridSize); + // Update score display + scoreDisplay.textContent = score; +} + +function updateSnake() { + if (!gameRunning) return; + // Move snake const head = { x: snake[0].x + direction.x, y: snake[0].y + direction.y }; @@ -47,6 +55,7 @@ function drawGame() { snake.some((segment) => segment.x === head.x && segment.y === head.y) ) { gameRunning = false; + clearInterval(gameInterval); // Stop the game loop return; } @@ -55,13 +64,12 @@ function drawGame() { // Check if snake eats food if (head.x === food.x && head.y === food.y) { score++; - scoreDisplay.textContent = score; placeFood(); } else { snake.pop(); } - requestAnimationFrame(drawGame); + drawGame(); } function placeFood() { @@ -84,16 +92,19 @@ function placeFood() { function startGame() { if (gameRunning) return; snake = [{ x: 10, y: 10 }]; - direction = { x: 1, y: 0 }; // Start moving to the right + direction = { x: 0, y: 0 }; // Initial direction: no movement score = 0; - scoreDisplay.textContent = score; placeFood(); gameRunning = true; drawGame(); + + // Start the game loop to update snake position every 500ms + gameInterval = setInterval(updateSnake, 500); } function resetGame() { gameRunning = false; + clearInterval(gameInterval); // Stop the game loop startGame(); }
commit dc7ce89b9c8bb54ce3deb03ae5c5f935d4d2e12f
Author: ffff:82.167.4.246 <ffff:82.167.4.246@snakescroll.scroll.pub> Date: 2024-12-28 11:02:49 +0000 Subject: updated script.js diff --git a/script.js b/script.js index 6f2b786..d2fb82c 100644 --- a/script.js +++ b/script.js @@ -1,41 +1,51 @@ -const canvas = document.getElementById('gameCanvas'); -const ctx = canvas.getContext('2d'); -const startButton = document.getElementById('startButton'); -const resetButton = document.getElementById('resetButton'); -const scoreDisplay = document.getElementById('score'); +const canvas = document.getElementById("gameCanvas"); +const ctx = canvas.getContext("2d"); +const startButton = document.getElementById("startButton"); +const resetButton = document.getElementById("resetButton"); +const scoreDisplay = document.getElementById("score"); const gridSize = 20; const tileCount = canvas.width / gridSize; -let snake = [{x: 10, y: 10}]; -let food = {x: 5, y: 5}; -let direction = {x: 0, y: 0}; +let snake = [{ x: 10, y: 10 }]; +let food = { x: 5, y: 5 }; +let direction = { x: 0, y: 0 }; let score = 0; let gameRunning = false; function drawGame() { if (!gameRunning) return; - + // Clear canvas - ctx.fillStyle = '#222'; + ctx.fillStyle = "#222"; ctx.fillRect(0, 0, canvas.width, canvas.height); // Draw snake - ctx.fillStyle = '#4CAF50'; - snake.forEach(segment => { - ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize); + ctx.fillStyle = "#4CAF50"; + snake.forEach((segment) => { + ctx.fillRect( + segment.x * gridSize, + segment.y * gridSize, + gridSize, + gridSize, + ); }); // Draw food - ctx.fillStyle = '#FF5252'; + ctx.fillStyle = "#FF5252"; ctx.fillRect(food.x * gridSize, food.y * gridSize, gridSize, gridSize); // Move snake - const head = {x: snake[0].x + direction.x, y: snake[0].y + direction.y}; + const head = { x: snake[0].x + direction.x, y: snake[0].y + direction.y }; // Check collision with walls or self - if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount || - snake.some(segment => segment.x === head.x && segment.y === head.y)) { + if ( + head.x < 0 || + head.x >= tileCount || + head.y < 0 || + head.y >= tileCount || + snake.some((segment) => segment.x === head.x && segment.y === head.y) + ) { gameRunning = false; return; } @@ -57,22 +67,24 @@ function drawGame() { function placeFood() { food = { x: Math.floor(Math.random() * tileCount), - y: Math.floor(Math.random() * tileCount) + y: Math.floor(Math.random() * tileCount), }; - + // Make sure food doesn't spawn on snake - while (snake.some(segment => segment.x === food.x && segment.y === food.y)) { + while ( + snake.some((segment) => segment.x === food.x && segment.y === food.y) + ) { food = { x: Math.floor(Math.random() * tileCount), - y: Math.floor(Math.random() * tileCount) + y: Math.floor(Math.random() * tileCount), }; } } function startGame() { if (gameRunning) return; - snake = [{x: 10, y: 10}]; - direction = {x: 0, y: 0}; + snake = [{ x: 10, y: 10 }]; + direction = { x: 1, y: 0 }; // Start moving to the right score = 0; scoreDisplay.textContent = score; placeFood(); @@ -85,24 +97,24 @@ function resetGame() { startGame(); } -window.addEventListener('keydown', e => { +window.addEventListener("keydown", (e) => { if (!gameRunning) return; - - switch(e.key) { - case 'ArrowUp': - if (direction.y === 0) direction = {x: 0, y: -1}; + + switch (e.key) { + case "ArrowUp": + if (direction.y === 0) direction = { x: 0, y: -1 }; break; - case 'ArrowDown': - if (direction.y === 0) direction = {x: 0, y: 1}; + case "ArrowDown": + if (direction.y === 0) direction = { x: 0, y: 1 }; break; - case 'ArrowLeft': - if (direction.x === 0) direction = {x: -1, y: 0}; + case "ArrowLeft": + if (direction.x === 0) direction = { x: -1, y: 0 }; break; - case 'ArrowRight': - if (direction.x === 0) direction = {x: 1, y: 0}; + case "ArrowRight": + if (direction.x === 0) direction = { x: 1, y: 0 }; break; } }); -startButton.addEventListener('click', startGame); -resetButton.addEventListener('click', resetGame); \ No newline at end of file +startButton.addEventListener("click", startGame); +resetButton.addEventListener("click", resetGame);
commit 4453c6db2d54d2ebc26da606f4eb129ed84f4d21
Author: root <root@hub.scroll.pub> Date: 2024-12-28 10:54:20 +0000 Subject: Initial commit diff --git a/body.html b/body.html new file mode 100644 index 0000000..2c5bf32 --- /dev/null +++ b/body.html @@ -0,0 +1,20 @@ +<header> + <h1>Snake Game</h1> + <p>Classic fun, modern design</p> +</header> + +<main> + <div class="game-container"> + <canvas id="gameCanvas" width="400" height="400"></canvas> + <div class="score-display"> + <span>Score: </span> + <span id="score">0</span> + </div> + <button id="startButton" class="game-button">Start Game</button> + <button id="resetButton" class="game-button">Reset Game</button> + </div> +</main> + +<footer> + <p>Enjoy the classic snake game experience!</p> +</footer> \ No newline at end of file diff --git a/index.scroll b/index.scroll new file mode 100644 index 0000000..8004921 --- /dev/null +++ b/index.scroll @@ -0,0 +1,8 @@ +buildHtml +baseUrl https://snakescroll.scroll.pub +metaTags +editButton /edit.html +title Snake Game - Classic Fun in Your Browser +style.css +body.html +script.js \ No newline at end of file diff --git a/prompt.json b/prompt.json new file mode 100644 index 0000000..f0562b5 --- /dev/null +++ b/prompt.json @@ -0,0 +1,25 @@ +{ + "id": "1a03b8a0-296d-4ed0-b95b-0a1a5024666d", + "object": "chat.completion", + "created": 1735383237, + "model": "deepseek-chat", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "---domain---\nsnakescroll.scroll.pub\n---index.scroll---\nbuildHtml\nbaseUrl https://snakescroll.scroll.pub\nmetaTags\neditButton /edit.html\ntitle Snake Game - Classic Fun in Your Browser\nstyle.css\nbody.html\nscript.js\n---body.html---\n<header>\n <h1>Snake Game</h1>\n <p>Classic fun, modern design</p>\n</header>\n\n<main>\n <div class=\"game-container\">\n <canvas id=\"gameCanvas\" width=\"400\" height=\"400\"></canvas>\n <div class=\"score-display\">\n <span>Score: </span>\n <span id=\"score\">0</span>\n </div>\n <button id=\"startButton\" class=\"game-button\">Start Game</button>\n <button id=\"resetButton\" class=\"game-button\">Reset Game</button>\n </div>\n</main>\n\n<footer>\n <p>Enjoy the classic snake game experience!</p>\n</footer>\n---style.css---\n:root {\n --primary-color: #4CAF50;\n --secondary-color: #45a049;\n --background-color: #f5f5f5;\n --text-color: #333;\n --canvas-color: #222;\n}\n\n* {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n}\n\nbody {\n font-family: 'Segoe UI', sans-serif;\n background-color: var(--background-color);\n color: var(--text-color);\n line-height: 1.6;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n}\n\nheader {\n background-color: var(--primary-color);\n color: white;\n padding: 2rem;\n text-align: center;\n}\n\nh1 {\n font-size: 2.5rem;\n margin-bottom: 0.5rem;\n}\n\nmain {\n flex: 1;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 2rem;\n}\n\n.game-container {\n text-align: center;\n background: white;\n padding: 2rem;\n border-radius: 10px;\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n}\n\ncanvas {\n background-color: var(--canvas-color);\n border-radius: 5px;\n margin-bottom: 1rem;\n}\n\n.score-display {\n font-size: 1.2rem;\n margin: 1rem 0;\n color: var(--primary-color);\n}\n\n.game-button {\n background-color: var(--primary-color);\n color: white;\n border: none;\n padding: 0.8rem 1.5rem;\n margin: 0.5rem;\n border-radius: 5px;\n cursor: pointer;\n font-size: 1rem;\n transition: background-color 0.3s ease;\n}\n\n.game-button:hover {\n background-color: var(--secondary-color);\n}\n\nfooter {\n background-color: var(--primary-color);\n color: white;\n text-align: center;\n padding: 1rem;\n}\n\n@media (max-width: 480px) {\n canvas {\n width: 300px;\n height: 300px;\n }\n\n h1 {\n font-size: 2rem;\n }\n}\n---script.js---\nconst canvas = document.getElementById('gameCanvas');\nconst ctx = canvas.getContext('2d');\nconst startButton = document.getElementById('startButton');\nconst resetButton = document.getElementById('resetButton');\nconst scoreDisplay = document.getElementById('score');\n\nconst gridSize = 20;\nconst tileCount = canvas.width / gridSize;\n\nlet snake = [{x: 10, y: 10}];\nlet food = {x: 5, y: 5};\nlet direction = {x: 0, y: 0};\nlet score = 0;\nlet gameRunning = false;\n\nfunction drawGame() {\n if (!gameRunning) return;\n \n // Clear canvas\n ctx.fillStyle = '#222';\n ctx.fillRect(0, 0, canvas.width, canvas.height);\n\n // Draw snake\n ctx.fillStyle = '#4CAF50';\n snake.forEach(segment => {\n ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);\n });\n\n // Draw food\n ctx.fillStyle = '#FF5252';\n ctx.fillRect(food.x * gridSize, food.y * gridSize, gridSize, gridSize);\n\n // Move snake\n const head = {x: snake[0].x + direction.x, y: snake[0].y + direction.y};\n\n // Check collision with walls or self\n if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount ||\n snake.some(segment => segment.x === head.x && segment.y === head.y)) {\n gameRunning = false;\n return;\n }\n\n snake.unshift(head);\n\n // Check if snake eats food\n if (head.x === food.x && head.y === food.y) {\n score++;\n scoreDisplay.textContent = score;\n placeFood();\n } else {\n snake.pop();\n }\n\n requestAnimationFrame(drawGame);\n}\n\nfunction placeFood() {\n food = {\n x: Math.floor(Math.random() * tileCount),\n y: Math.floor(Math.random() * tileCount)\n };\n \n // Make sure food doesn't spawn on snake\n while (snake.some(segment => segment.x === food.x && segment.y === food.y)) {\n food = {\n x: Math.floor(Math.random() * tileCount),\n y: Math.floor(Math.random() * tileCount)\n };\n }\n}\n\nfunction startGame() {\n if (gameRunning) return;\n snake = [{x: 10, y: 10}];\n direction = {x: 0, y: 0};\n score = 0;\n scoreDisplay.textContent = score;\n placeFood();\n gameRunning = true;\n drawGame();\n}\n\nfunction resetGame() {\n gameRunning = false;\n startGame();\n}\n\nwindow.addEventListener('keydown', e => {\n if (!gameRunning) return;\n \n switch(e.key) {\n case 'ArrowUp':\n if (direction.y === 0) direction = {x: 0, y: -1};\n break;\n case 'ArrowDown':\n if (direction.y === 0) direction = {x: 0, y: 1};\n break;\n case 'ArrowLeft':\n if (direction.x === 0) direction = {x: -1, y: 0};\n break;\n case 'ArrowRight':\n if (direction.x === 0) direction = {x: 1, y: 0};\n break;\n }\n});\n\nstartButton.addEventListener('click', startGame);\nresetButton.addEventListener('click', resetGame);\n---end---" + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 239, + "completion_tokens": 1509, + "total_tokens": 1748, + "prompt_cache_hit_tokens": 0, + "prompt_cache_miss_tokens": 239 + }, + "system_fingerprint": "fp_f1afce2943" +} \ No newline at end of file diff --git a/readme.scroll b/readme.scroll new file mode 100644 index 0000000..9570104 --- /dev/null +++ b/readme.scroll @@ -0,0 +1,2 @@ +# snakescroll.scroll.pub +Website generated by DeepSeek from prompt: Website to play snake game \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..6f2b786 --- /dev/null +++ b/script.js @@ -0,0 +1,108 @@ +const canvas = document.getElementById('gameCanvas'); +const ctx = canvas.getContext('2d'); +const startButton = document.getElementById('startButton'); +const resetButton = document.getElementById('resetButton'); +const scoreDisplay = document.getElementById('score'); + +const gridSize = 20; +const tileCount = canvas.width / gridSize; + +let snake = [{x: 10, y: 10}]; +let food = {x: 5, y: 5}; +let direction = {x: 0, y: 0}; +let score = 0; +let gameRunning = false; + +function drawGame() { + if (!gameRunning) return; + + // Clear canvas + ctx.fillStyle = '#222'; + ctx.fillRect(0, 0, canvas.width, canvas.height); + + // Draw snake + ctx.fillStyle = '#4CAF50'; + snake.forEach(segment => { + ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize); + }); + + // Draw food + ctx.fillStyle = '#FF5252'; + ctx.fillRect(food.x * gridSize, food.y * gridSize, gridSize, gridSize); + + // Move snake + const head = {x: snake[0].x + direction.x, y: snake[0].y + direction.y}; + + // Check collision with walls or self + if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount || + snake.some(segment => segment.x === head.x && segment.y === head.y)) { + gameRunning = false; + return; + } + + snake.unshift(head); + + // Check if snake eats food + if (head.x === food.x && head.y === food.y) { + score++; + scoreDisplay.textContent = score; + placeFood(); + } else { + snake.pop(); + } + + requestAnimationFrame(drawGame); +} + +function placeFood() { + food = { + x: Math.floor(Math.random() * tileCount), + y: Math.floor(Math.random() * tileCount) + }; + + // Make sure food doesn't spawn on snake + while (snake.some(segment => segment.x === food.x && segment.y === food.y)) { + food = { + x: Math.floor(Math.random() * tileCount), + y: Math.floor(Math.random() * tileCount) + }; + } +} + +function startGame() { + if (gameRunning) return; + snake = [{x: 10, y: 10}]; + direction = {x: 0, y: 0}; + score = 0; + scoreDisplay.textContent = score; + placeFood(); + gameRunning = true; + drawGame(); +} + +function resetGame() { + gameRunning = false; + startGame(); +} + +window.addEventListener('keydown', e => { + if (!gameRunning) return; + + switch(e.key) { + case 'ArrowUp': + if (direction.y === 0) direction = {x: 0, y: -1}; + break; + case 'ArrowDown': + if (direction.y === 0) direction = {x: 0, y: 1}; + break; + case 'ArrowLeft': + if (direction.x === 0) direction = {x: -1, y: 0}; + break; + case 'ArrowRight': + if (direction.x === 0) direction = {x: 1, y: 0}; + break; + } +}); + +startButton.addEventListener('click', startGame); +resetButton.addEventListener('click', resetGame); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..a9cd931 --- /dev/null +++ b/style.css @@ -0,0 +1,97 @@ +:root { + --primary-color: #4CAF50; + --secondary-color: #45a049; + --background-color: #f5f5f5; + --text-color: #333; + --canvas-color: #222; +} + +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: 'Segoe UI', sans-serif; + background-color: var(--background-color); + color: var(--text-color); + line-height: 1.6; + min-height: 100vh; + display: flex; + flex-direction: column; +} + +header { + background-color: var(--primary-color); + color: white; + padding: 2rem; + text-align: center; +} + +h1 { + font-size: 2.5rem; + margin-bottom: 0.5rem; +} + +main { + flex: 1; + display: flex; + justify-content: center; + align-items: center; + padding: 2rem; +} + +.game-container { + text-align: center; + background: white; + padding: 2rem; + border-radius: 10px; + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); +} + +canvas { + background-color: var(--canvas-color); + border-radius: 5px; + margin-bottom: 1rem; +} + +.score-display { + font-size: 1.2rem; + margin: 1rem 0; + color: var(--primary-color); +} + +.game-button { + background-color: var(--primary-color); + color: white; + border: none; + padding: 0.8rem 1.5rem; + margin: 0.5rem; + border-radius: 5px; + cursor: pointer; + font-size: 1rem; + transition: background-color 0.3s ease; +} + +.game-button:hover { + background-color: var(--secondary-color); +} + +footer { + background-color: var(--primary-color); + color: white; + text-align: center; + padding: 1rem; +} + +@media (max-width: 480px) { + canvas { + width: 300px; + height: 300px; + } + + h1 { + font-size: 2rem; + } +} \ No newline at end of file