{"id":217227,"student_id":3525,"content":"var x = 0; //挖洞機的 X 座標\nvar y = 0; //挖洞機的 Y 座標\nvar width = 20; //格子大小\n\nvar arr = [];\n\nforever(loop);\n\n// 遊戲主迴圈\nfunction loop () {\n pen.fillColor = \"Red\";\n pen.drawRect(x*width+1, y*width+1, width-2, width-2);\n \n \n if (maze[x-1][y].color == \"white\") {\n arr.push(\"left\");\n }\n if (maze[x+1][y].color == \"white\") {\n arr.push(\"right\");\n }\n if (maze[x][y-1].color == \"white\") {\n arr.push(\"up\");\n }\n if (maze[x][y+1].color == \"white\") {\n arr.push(\"down\");\n }\n // print(arr.length, 10, 10, \"blue\", 30);\n \n maze[x][y].color = \"lightblue\";\n \n let rand = Math.floor(Math.random() * arr.length);\n let next = arr[rand];\n \n // if (next == \"up\") {\n // maze[x][y].up = true;\n // y -= 1;\n // maze[x][y].down = true;\n // } \n // else if (next == \"down\"){\n // maze[x][y].down = true;\n // y += 1;\n // maze[x][y].up = true;\n // } \n // else if (next == \"left\"){\n // maze[x][y].left = true;\n // x -= 1;\n // maze[x][y].right = true;\n // } \n // else if (next == \"right\"){\n // maze[x][y].right = true;\n // x += 1;\n // maze[x][y].left = true;\n // }else{\n // maze[x][y].color = \"yellow\";\n \n // if (maze[x][y].right \u0026\u0026 maze[x+1][y].color == \"lightblue\") {\n // x += 1;\n // } else if (maze[x][y].left \u0026\u0026 maze[x-1][y].color == \"lightblue\") {\n // x -= 1;\n // } else if (maze[x][y].down \u0026\u0026 maze[x][y+1].color == \"lightblue\") {\n // y += 1;\n // } else if (maze[x][y].up \u0026\u0026 maze[x][y-1].color == \"lightblue\") {\n // y -= 1;\n // }\n // }\n switch (next) {\n case 'up':\n maze[x][y].up = true;\n y -= 1;\n maze[x][y].down = true;\n break;\n case 'down':\n maze[x][y].down = true;\n y += 1;\n maze[x][y].up = true;\n break;\n case 'left':\n maze[x][y].left = true;\n x -= 1;\n maze[x][y].right = true;\n break;\n case 'right':\n maze[x][y].right = true;\n x += 1;\n maze[x][y].left = true;\n break;\n default:\n maze[x][y].color = \"yellow\";\n \n if (maze[x][y].right \u0026\u0026 maze[x+1][y].color == \"lightblue\") {x += 1;}\n else if (maze[x][y].left \u0026\u0026 maze[x-1][y].color == \"lightblue\") {x -= 1;}\n else if (maze[x][y].down \u0026\u0026 maze[x][y+1].color == \"lightblue\") {y += 1;}\n else if (maze[x][y].up \u0026\u0026 maze[x][y-1].color == \"lightblue\") {y -= 1;}\n }\n \n arr = [];\n}\n","created_at":"2021-01-09T10:15:12.763+08:00","updated_at":"2025-10-05T23:01:07.983+08:00","name":"迷宮產生器(預設版) 副本","language":"javascript","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/217227/7dbf7e8f3aaac13ad1d1b0bc7b1277ed.jpg"},"parent_id":157103,"plugin":"var maze = [];\nvar width = 20;\nvar row = 640/width;\nvar col = 480/width;\n\nfor (var x = -1; x \u003c row + 1; x++) {\n maze[x] = [];\n for (var y = -1; y \u003c col + 1; y++) {\n var color = x == -1 || y == -1 || x == row || y == col ? 'black' : 'white';\n maze[x][y] = {\n color: color,\n up: false,\n right: false,\n down: false,\n left: false\n };\n }\n}\n\nforever(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.001;\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 }\n});\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":63,"hashid":"5j3s936pj","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
繁中
简中
English
日本語
1:1:1
1:1
全寬
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦