{"id":159406,"student_id":10,"content":"\n\nforever(function(){\n\n\n for (var x = 0; x \u003c width; x++) {\n for (var y = 0; y \u003c height; y++) {\n var c = grid[x][y];\n if (body.includes(c) == false) c.color = 'white';\n }\n }\n \n var arr = [body[0]];\n \n while(arr.length \u003e 0) {\n var t = arr.shift();\n \n if (t == food) break;\n \n if (t.up.color === 'white') {\n t.up.from = t;\n t.up.color = 'lightblue';\n arr.push(t.up);\n }\n if (t.down.color === 'white') {\n t.down.from = t;\n t.down.color = 'lightblue';\n arr.push(t.down);\n }\n if (t.left.color === 'white') {\n t.left.from = t;\n t.left.color = 'lightblue';\n arr.push(t.left);\n }\n if (t.right.color === 'white') {\n t.right.from = t;\n t.right.color = 'lightblue';\n arr.push(t.right);\n }\n }\n \n var tmp = food;\n while(tmp.from) {\n tmp = tmp.from;\n tmp.color = 'yellow';\n if (tmp == body[0]) break;\n }\n \n if (body[0].up.color == 'yellow') direction = 'up';\n if (body[0].down.color == 'yellow') direction = 'down';\n if (body[0].left.color == 'yellow') direction = 'left';\n if (body[0].right.color == 'yellow') direction = 'right';\n\n})","created_at":"2020-06-15T18:06:13.653+08:00","updated_at":"2020-06-15T18:06:32.179+08:00","name":"貪食蛇AI _ 雛形","language":"javascript","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/159406/f6402e0214b551790d380804c6a854bb.jpg"},"parent_id":2,"plugin":"// noprotect\nsetBackdrop(\"black\");\n\nvar grid = {}\nvar width = 32;\nvar height = 24;\n\nfor (var x = -1; x \u003c= width; x++) {\n grid[x] = {};\n for (var y = -1; y \u003c= height; y++) {\n grid[x][y] = {\n color: 'white',\n steps: 0,\n from: undefined,\n x,\n y,\n }\n }\n}\n\nfor (var x = 0; x \u003c width; x++) {\n grid[x][-1] = grid[x][height - 1]\n grid[x][height] = grid[x][0]\n}\n\nfor (var y = 0; y \u003c height; y++) {\n grid[-1][y] = grid[width - 1][y]\n grid[width][y] = grid[0][y]\n}\n\nfor (var x = 0; x \u003c width; x++) {\n for (var y = 0; y \u003c height; y++) {\n grid[x][y].up = grid[x][y - 1];\n grid[x][y].down = grid[x][y + 1];\n grid[x][y].left = grid[x - 1][y];\n grid[x][y].right = grid[x + 1][y];\n }\n}\n\n\n\nvar body = []\nvar direction = 'right';\nvar clock = 0;\nvar food = grid[5][5];\n\nbody.push(grid[9][0]);\nbody.push(grid[8][0]);\nbody.push(grid[7][0]);\nbody.push(grid[6][0]);\nbody.push(grid[5][0]);\nbody.push(grid[4][0]);\nbody.push(grid[3][0]);\nbody.push(grid[2][0]);\nbody.push(grid[1][0]);\nbody.push(grid[0][0]);\n\nforever(function() {\n \n for (var x = 0; x \u003c width; x++) {\n for (var y = 0; y \u003c height; y++) {\n var c = grid[x][y];\n pen.fillColor = c.color;\n pen.drawRect(c.x*20, c.y*20, 20, 20);\n }\n }\n \n \n // setBackdrop(\"black\");\n body.forEach(function (b) {\n // pen.fillColor = 'black';\n // pen.drawRect(b.x*20, b.y*20, 20, 20);\n b.color = 'black';\n });\n\n pen.fillColor = 'red';\n pen.drawRect(food.x*20, food.y*20, 20, 20);\n\n if (key.up) direction = 'up';\n if (key.down) direction = 'down';\n if (key.left) direction = 'left';\n if (key.right) direction = 'right';\n\n clock++;\n if (clock%2 == 0) {\n body.pop();\n if (direction == 'up') body.unshift(body[0].up);\n if (direction == 'down') body.unshift(body[0].down);\n if (direction == 'left') body.unshift(body[0].left);\n if (direction == 'right') body.unshift(body[0].right);\n\n if (body[0] === food) {\n body.unshift(food);\n for (var i=0; i\u003c1000; i++) {\n var randX = Math.floor(Math.random()*32);\n var randY = Math.floor(Math.random()*24);\n food = grid[randX][randY];\n if (food.color != 'black') break;\n }\n }\n \n if (body[0].color == 'black') stop\n }\n\n \n})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":263,"hashid":"4y3sv32m","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2777070,"file_name":"earth.png","project_id":159406,"asset_id":230736,"created_at":"2020-06-15T18:06:23.670+08:00","updated_at":"2020-06-15T18:06:23.670+08:00"},{"id":2777071,"file_name":"space_bg.jpg","project_id":159406,"asset_id":230737,"created_at":"2020-06-15T18:06:23.676+08:00","updated_at":"2020-06-15T18:06:23.676+08:00"},{"id":2777072,"file_name":"koding.png","project_id":159406,"asset_id":230738,"created_at":"2020-06-15T18:06:23.681+08:00","updated_at":"2020-06-15T18:06:23.681+08:00"},{"id":2777073,"file_name":"Gymnopedie_No_1.mp3","project_id":159406,"asset_id":230739,"created_at":"2020-06-15T18:06:23.707+08:00","updated_at":"2020-06-15T18:06:23.707+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦