Grok3-- built a classic snake game for Dashboard!

smanjunath211
Tue, 11 Mar 2025 11:21:32 +0000
Share Your Projects

I asked Grok3 to create a flow to simulate classic snake game and without a single human intervention, this is what it gave me..!

Just wow!

[{"id":"game_template","type":"ui-template","z":"snake-game","group":"4b8f3787bb30f542","page":"game_page","name":"Snake Game","order":1,"width":"4","height":"4","format":" \n \n Score: 0 \n \n\n \n (function() {\n const canvas = document.getElementById('gameCanvas');\n const ctx = canvas.getContext('2d');\n const gridSize = 20;\n const tileCount = canvas.width / gridSize;\n let snake = [{ x: 10, y: 10 }];\n let food = { x: 15, y: 15 };\n let dx = 0;\n let dy = 0;\n let score = 0;\n let gameLoop;\n\n function drawGame() {\n // Move snake\n const head = { x: snake[0].x + dx, y: snake[0].y + dy };\n snake.unshift(head);\n\n // Check food collision\n if (head.x === food.x && head.y === food.y) {\n score += 10;\n document.getElementById('score').innerText = score;\n spawnFood();\n } else {\n snake.pop();\n }\n\n // Check wall collision\n if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount) {\n gameOver();\n return;\n }\n\n // Check self collision\n for (let i = 1; i < snake.length; i++) {\n if (head.x === snake[i].x && head.y === snake[i].y) {\n gameOver();\n return;\n }\n }\n\n // Clear canvas\n ctx.fillStyle = 'black';\n ctx.fillRect(0, 0, canvas.width, canvas.height);\n\n // Draw snake\n ctx.fillStyle = 'lime';\n snake.forEach(segment => {\n ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize - 2, gridSize - 2);\n });\n\n // Draw food\n ctx.fillStyle = 'red';\n ctx.fillRect(food.x * gridSize, food.y * gridSize, gridSize - 2, gridSize - 2);\n }\n\n function spawnFood() {\n food.x = Math.floor(Math.random() * tileCount);\n food.y = Math.floor(Math.random() * tileCount);\n }\n\n function gameOver() {\n clearInterval(gameLoop);\n alert('Game Over! Score: ' + score);\n snake = [{ x: 10, y: 10 }];\n dx = 0;\n dy = 0;\n score = 0;\n document.getElementById('score').innerText = score;\n spawnFood();\n gameLoop = setInterval(drawGame, 100);\n }\n\n document.addEventListener('keydown', (e) => {\n switch (e.key) {\n case 'ArrowUp': if (dy === 0) { dx = 0; dy = -1; } break;\n case 'ArrowDown': if (dy === 0) { dx = 0; dy = 1; } break;\n case 'ArrowLeft': if (dx === 0) { dx = -1; dy = 0; } break;\n case 'ArrowRight': if (dx === 0) { dx = 1; dy = 0; } break;\n }\n });\n\n spawnFood();\n gameLoop = setInterval(drawGame, 100);\n })();\n ","storeOutMessages":false,"passthru":false,"templateScope":"local","className":"","x":350,"y":120,"wires":[[]]},{"id":"4b8f3787bb30f542","type":"ui-group","name":"Dates","page":"c8690e5bce80ab2a","width":"6","height":"1","order":2,"showTitle":false,"className":"","visible":"true","disabled":"false","groupType":"default"},{"id":"game_page","type":"ui-page","z":"snake_game_flow","name":"Snake","ui":"0aa5ac292a3ec726","path":"/snake","icon":"","layout":"grid","theme":"acc4d7417e8a63c7","breakpoints":[{"name":"Default","px":"0","cols":"3"},{"name":"Tablet","px":"576","cols":"6"},{"name":"Small Desktop","px":"768","cols":"9"},{"name":"Desktop","px":"1024","cols":"12"}],"order":2,"className":"","visible":"true","disabled":"false"},{"id":"c8690e5bce80ab2a","type":"ui-page","name":"ANALYSIS","ui":"0aa5ac292a3ec726","path":"/analysis","icon":"database-eye","layout":"flex","theme":"b0fed2b0e19988c3","breakpoints":[{"name":"Default","px":"0","cols":"3"},{"name":"Tablet","px":"576","cols":"6"},{"name":"Small Desktop","px":"768","cols":"9"},{"name":"Desktop","px":"1024","cols":"24"}],"order":5,"className":"","visible":true,"disabled":false},{"id":"0aa5ac292a3ec726","type":"ui-base","name":"My Dashboard","path":"/dashboard","appIcon":"","includeClientData":false,"acceptsClientConfig":["ui-notification","ui-control","ui-form","ui-text-input","ui-number-input","ui-file-input","ui-button","ui-button-group","ui-radio-group","ui-slider","ui-switch","ui-text","ui-table","ui-chart","ui-gauge","ui-markdown","ui-template","ui-tabulator"],"showPathInSidebar":true,"showPageTitle":true,"navigationStyle":"temporary","titleBarStyle":"fixed","showReconnectNotification":true,"notificationDisplayTime":"1","showDisconnectNotification":true},{"id":"acc4d7417e8a63c7","type":"ui-theme","name":"STD_THEME","colors":{"surface":"#ffffff","primary":"#0094ce","bgPage":"#eeeeee","groupBg":"#ffffff","groupOutline":"#cccccc"},"sizes":{"density":"default","pagePadding":"0px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"4px"}},{"id":"b0fed2b0e19988c3","type":"ui-theme","name":"MyTheme","colors":{"surface":"#000000","primary":"#059bd6","bgPage":"#050505","groupBg":"#303030","groupOutline":"#297500"},"sizes":{"density":"default","pagePadding":"2px","groupGap":"10px","groupBorderRadius":"10px","widgetGap":"2px"}}]

2 posts - 2 participants