{"id":213432,"student_id":3439,"content":"// 老鼠初始化的位置\nvar x = 0;\nvar y = 0;\nvar width = 20;\n\nforever(loop);\n\n// 遊戲迴圈\nfunction loop () {\n pen.fillColor = 'orange'\n pen.drawRect(31*width+1, 23*width+1, width-2, width-2)\n pen.fillColor = 'red'\n pen.drawRect(x*width+1, y*width+1, width-2, width-2)\n \n if (x == 31 \u0026\u0026 y == 23) {\n stop()\n }\n\n maze[x][y].color = 'lightblue'\n\n if (maze[x+1][y].color == 'white' \u0026\u0026 maze[x][y].right) {\n x += 1\n } else if (maze[x][y+1].color == 'white' \u0026\u0026 maze[x][y].down) {\n y += 1\n } else if (maze[x][y-1].color == 'white' \u0026\u0026 maze[x][y].up) {\n y -= 1\n } else if (maze[x-1][y].color == 'white' \u0026\u0026 maze[x][y].left) {\n x -= 1\n } else {\n maze[x][y].color = 'yellow'\n\n if (maze[x][y-1].color == 'lightblue' \u0026\u0026 maze[x][y].up) {\n y -= 1\n } else if (maze[x][y+1].color == 'lightblue' \u0026\u0026 maze[x][y].down) {\n y += 1\n } else if (maze[x+1][y].color == 'lightblue' \u0026\u0026 maze[x][y].right) {\n x += 1\n } else if (maze[x-1][y].color == 'lightblue' \u0026\u0026 maze[x][y].left) {\n x -= 1\n }\n\n }\n}","created_at":"2020-12-19T13:33:27.954+08:00","updated_at":"2020-12-19T15:15:10.552+08:00","name":"老鼠走迷宮(預設版) 副本","language":"javascript","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/213432/82d9f6a299732aea8f52561723639584.jpg"},"parent_id":156772,"plugin":"var maze = (function () {\n \n var maze = [];\n var width = 20;\n var row = 640/width;\n var col = 480/width;\n \n for (var x = -1; x \u003c row + 1; x++) {\n maze[x] = {};\n for (var y = -1; y \u003c col + 1; y++) {\n maze[x][y] = {\n color: '#ffffff',\n up: false,\n right: false,\n down: false,\n left: false\n };\n }\n }\n \n forever(function() {\n for (var cx = 0; cx \u003c row; cx++) {\n for (var cy = 0; cy \u003c col; cy++) {\n \n var cell = maze[cx][cy];\n pen.size = 0.000001;\n pen.fillColor = cell.color;\n pen.drawRect(cx*width, cy*width, width, width);\n \n pen.size = 1;\n var x = cx*width;\n var y = cy*width;\n if (!cell.up) pen.drawLine(x, y, x + width, y);\n if (!cell.right) pen.drawLine(x + width, y, x + width, y + width);\n if (!cell.down) pen.drawLine(x, y + width, x + width, y + width);\n if (!cell.left) pen.drawLine(x, y + width, x, y);\n \n pen.size = 0.000001;\n }\n }\n });\n \n var x = 0;\n var y = 0;\n var steps = [];\n maze[0][0].color = 'lightblue';\n \n while(true) {\n pen.fillColor = 'red';\n pen.drawRect(x*width, y*width, width, width);\n \n var next = getNeighbors();\n if (next.length \u003e 0) {\n steps.push({x: x, y: y});\n \n var rand = Math.floor(Math.random()*next.length);\n if (next[rand] == 'up') {\n maze[x][y].up = true;\n y -= 1;\n maze[x][y].down = true;\n }\n if (next[rand] == 'right') {\n maze[x][y].right = true;\n x += 1;\n maze[x][y].left = true;\n }\n if (next[rand] == 'down') {\n maze[x][y].down = true;\n y += 1;\n maze[x][y].up = true;\n }\n if (next[rand] == 'left') {\n maze[x][y].left = true;\n x -= 1;\n maze[x][y].right = true;\n }\n maze[x][y].color = 'lightblue';\n } else {\n maze[x][y].color = 'white';\n if (steps.length \u003e 0) {\n var back = steps.pop();\n x = back.x;\n y = back.y;\n }\n }\n \n var count = 0;\n for (var c1 = 0; c1 \u003c row; c1++) {\n for (var c2 = 0; c2 \u003c col; c2++) {\n if (maze[c1][c2].color == 'white') {\n count++;\n }\n }\n }\n if (count \u003e= row*col) break;\n };\n \n function getNeighbors () {\n var arr = [];\n if (check(x + 1, y)) {\n arr.push('right');\n }\n if (check(x - 1, y)) {\n arr.push('left');\n }\n if (check(x, y + 1)) {\n arr.push('down');\n }\n if (check(x, y - 1)) {\n arr.push('up');\n }\n return arr;\n }\n \n function check (x, y) {\n return x \u003e= 0 \u0026\u0026 x \u003c row \u0026\u0026\n y \u003e= 0 \u0026\u0026 y \u003c col \u0026\u0026\n maze[x][y].color == '#ffffff';\n }\n \n return maze;\n})();","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":46,"hashid":"meysw64ry","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦