{"id":64420,"student_id":45,"content":"// 挖洞機的 x, y 位置\nvar x = 0;\nvar y = 0;\nvar a=true\n// 預設起始點被挖掘過\nmaze[0][0].color = '#AA7700';\n\nforever(function() {\n pen.fillColor = '#AAAAAA';\n pen.drawRect(x*width + 1, y*width + 1, width - 2, width - 2);\n var next = getNeighbors (x, y);\n if (next.length \u003e 0) {\n var ran = Math.floor(Math.random()*next.length);\n if (next[ran] == \"bottom\") {\n maze[x][y].bottom = true;\n y++;\n maze[x][y].top = true;\n }\n if (next[ran] == \"top\") {\n maze[x][y].top = true;\n y--;\n maze[x][y].bottom = true;\n }\n if (next[ran] == \"right\") {\n maze[x][y].right = true;\n x++;\n maze[x][y].left = true;\n }\n if (next[ran] == \"left\") {\n maze[x][y].left = true;\n x--;\n maze[x][y].right = true;\n }\n maze[x][y].color = '#AA7700';\n } else {\n maze[x][y].color = \"#B8860B\";\n if (maze[x][y].right \u0026\u0026 maze[x+1][y].color === \"#AA7700\") {\n x += 1;\n } else if (maze[x][y].bottom \u0026\u0026 maze[x][y+1].color === \"#AA7700\") {\n y += 1;\n } else if (maze[x][y].left \u0026\u0026 maze[x-1][y].color === \"#AA7700\") {\n x -= 1;\n } else if (maze[x][y].top \u0026\u0026 maze[x][y-1].color === \"#AA7700\") {\n y -= 1;\n }}\n if (maze[0][0].color === \"#B8860B\"|| maze[0][0].color == \"lightgreen\") {\n // 繪製黑色老鼠\n pen.fillColor = '#696969';\n pen.drawRect(x*width + 1, y*width + 1, width - 2, width - 2);\n maze[x][y].color = \"lightgreen\"; maze[31][23].color = \"yellow\";\n if (maze[x][y].color === \"yellow\") {\n a = false;\n }\n if (a) {\n if (maze[x][y].right \u0026\u0026 (maze[x+1][y].color === \"#B8860B\" || maze[x+1][y].color === \"yellow\")) {\n x += 1;\n } else if (maze[x][y].bottom \u0026\u0026 (maze[x][y+1].color === \"#B8860B\" || maze[x][y+1].color === \"yellow\")) {\n y += 1;\n } else if (maze[x][y].left \u0026\u0026 (maze[x-1][y].color === \"#B8860B\" || maze[x-1][y].color === \"yellow\")) {\n x -= 1;\n } else if (maze[x][y].top \u0026\u0026 (maze[x][y-1].color === \"#B8860B\" || maze[x][y-1].color === \"yellow\")) {\n y -= 1;\n } else {\n maze[x][y].color = \"#008800\";\n if (maze[x][y].right \u0026\u0026 maze[x+1][y].color === \"lightgreen\") {\n x += 1;\n } else if (maze[x][y].bottom \u0026\u0026 maze[x][y+1].color === \"lightgreen\") {\n y += 1;\n } else if (maze[x][y].left \u0026\u0026 maze[x-1][y].color === \"lightgreen\") {\n x -= 1;\n } else if (maze[x][y].top \u0026\u0026 maze[x][y-1].color === \"lightgreen\") {\n y -= 1;\n }\n }\n }}\n});\n\n// 取得四個方向中可以挖掘的方向\nfunction getNeighbors (x, y) {\n var a = [];\n if (x \u003c 31 \u0026\u0026 maze[x+1][y].color === \"white\") {\n a.push(\"right\");\n //console.log(a)\n } if (y \u003c 23 \u0026\u0026 maze[x][y+1].color === \"white\") {\n a.push(\"bottom\");\n //console.log(a)\n } if (x \u003e 0 \u0026\u0026 maze[x-1][y].color === \"white\") {\n a.push(\"left\");\n //console.log(a)\n } if (y \u003e 0 \u0026\u0026 maze[x][y-1].color === \"white\") {\n a.push(\"top\");\n //console.log(a)\n }\n return a\n\n}","created_at":"2019-04-27T13:34:23.386+08:00","updated_at":"2019-11-11T04:34:36.763+08:00","name":"迷宮產生器 副本","language":"javascript","screenshot":{"url":"https://cdn3.koding.school/uploads/project/screenshot/64420/fd1ac05835b665cf0d7e3c5532c7c2d7.jpg"},"parent_id":31658,"plugin":"var maze = [];\nvar width = 20;\nvar row = 640/width;\nvar col = 480/width;\n\nfor (var x = 0; x \u003c row; x++) {\n maze[x] = [];\n for (var y = 0; y \u003c col; y++) {\n maze[x][y] = {\n color: 'white',\n top: false,\n right: false,\n bottom: 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.top) pen.drawLine(x, y, x + width, y);\n if (!cell.right) pen.drawLine(x + width, y, x + width, y + width);\n if (!cell.bottom) pen.drawLine(x, y + width, x + width, y + width);\n if (!cell.left) pen.drawLine(x, y + width, x, y);\n }\n }\n});","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":46,"hashid":"kdmsgr6e","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
到這台電腦