{"id":28905,"student_id":10,"content":"var world = new World(.3); // 初始化地圖\nvar hero = world.setHero(1, 1); // 設定角色位置\nvar end = world.setEnd(30, 21); // 設定寶箱位置\n\nvar explorer = [hero];\n\nforever(function () {\n\n if (explorer.length \u003e 0) {\n \n explorer.sort(function (a, b) {\n return a.distanceTo(end) - b.distanceTo(end); \n });\n \n var e = explorer.shift();\n e.color = 'orange';\n \n if (e.right \u0026\u0026 e.right.color == undefined) {\n e.right.color = 'blue';\n e.right.from = e;\n explorer.push(e.right);\n }\n if (e.top \u0026\u0026 e.top.color == undefined) {\n e.top.color = 'blue';\n e.top.from = e;\n explorer.push(e.top);\n }\n if (e.left \u0026\u0026 e.left.color == undefined) {\n e.left.color = 'blue';\n e.left.from = e;\n explorer.push(e.left);\n }\n if (e.bottom \u0026\u0026 e.bottom.color == undefined) {\n e.bottom.color = 'blue';\n e.bottom.from = e;\n explorer.push(e.bottom);\n }\n \n if (e == end) {\n explorer.length = 0;\n }\n } else {\n end.color = 'red';\n var b = end.from;\n while(b) {\n b.color = 'red';\n b = b.from;\n }\n }\n});","created_at":"2018-05-15T22:29:47.239+08:00","updated_at":"2024-01-16T13:11:55.883+08:00","name":"BestFS 搜尋","language":"javascript","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/28905/0eac7cb298b6e5a13858213164a012a2.jpg"},"parent_id":2,"plugin":"setBackdrop('#333333');\n\nvar World = function (rate) {\n \n var W = 20;\n var rows = 640/W;\n var cols = 480/W;\n var grid = [];\n \n for (var x = -1; x \u003c= rows; x++) {\n grid[x] = [];\n for (var y = -1; y \u003c= cols; y++) {\n var s = createSprite([\"grass.png\", \"wall.png\"]);\n s.scale = 0.333;\n s.x = x*W + W/2;\n s.y = y*W + W/2;\n s.step = Infinity;\n s.connects = [];\n \n if (x == -1 || y == -1 || x == rows || y == rows) {\n s.costumeId = 1;\n } else {\n s.costumeId = Math.random() \u003c rate ? 1 : 0;\n }\n grid[x][y] = s;\n }\n }\n \n connects();\n \n forever(function(){\n for (var x = 0; x \u003c rows; x++) {\n for (var y = 0; y \u003c cols; y++) {\n if (grid[x][y].color != undefined) {\n grid[x][y].opacity = 0.6;\n pen.size = 0;\n pen.fillColor = grid[x][y].color;\n pen.drawRect(x*W, y*W, W, W);\n } else {\n grid[x][y].opacity = 1;\n }\n }\n }\n });\n \n function connects () {\n for (var x = 0; x \u003c rows; x++) {\n for (var y = 0; y \u003ccols; y++) {\n grid[x][y].left = undefined;\n grid[x][y].right = undefined;\n grid[x][y].bottom = undefined;\n grid[x][y].top = undefined;\n if (grid[x - 1][y].costumeId == 0)\n grid[x][y].left = grid[x - 1][y];\n if (grid[x][y - 1].costumeId == 0)\n grid[x][y].top = grid[x][y - 1];\n if (grid[x + 1][y].costumeId == 0)\n grid[x][y].right = grid[x + 1][y];\n if (grid[x][y + 1].costumeId == 0)\n grid[x][y].bottom = grid[x][y + 1];\n }\n }\n }\n \n function setHero (x, y) {\n if (x \u003c 0 || y \u003c 0 || x \u003e= rows || y \u003e= cols) return;\n var hero = createSprite('hero.png');\n hero.scale = 0.7;\n hero.x = x*W + W/2;\n hero.y = y*W + W/2 - 15;\n clearRect(x, y);\n return grid[x][y];\n }\n \n function setEnd (x, y) {\n if (x \u003c 0 || y \u003c 0 || x \u003e= rows || y \u003e= cols) return;\n var end = createSprite('box.png');\n end.scale = 0.7;\n end.x = x*W + W/2;\n end.y = y*W + W/2;\n clearRect(x, y);\n return grid[x][y];\n }\n\n function clearRect (x, y) {\n clear(x, y-2);\n clear(x-1, y-1);\n clear(x-0, y-1);\n clear(x+1, y-1);\n clear(x-2, y);\n clear(x-1, y);\n clear(x, y);\n clear(x+1, y);\n clear(x+2, y);\n clear(x-1, y+1);\n clear(x-0, y+1);\n clear(x+1, y+1);\n clear(x, y+2);\n connects();\n }\n \n function clear (x, y) {\n if (x \u003e= 0 \u0026\u0026 x \u003c rows \u0026\u0026 y \u003e= 0 \u0026\u0026 y \u003c cols) {\n grid[x][y].costumeId = 0;\n }\n }\n\n return {\n grid: grid,\n setHero: setHero,\n setEnd: setEnd\n }\n};\n\n\n\n\n\n\n\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":334,"hashid":"meys96zy","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":591622,"file_name":"box.png","project_id":28905,"asset_id":71533,"created_at":"2018-06-15T14:16:29.109+08:00","updated_at":"2018-06-15T14:16:29.109+08:00"},{"id":591623,"file_name":"hero.png","project_id":28905,"asset_id":71534,"created_at":"2018-06-15T14:16:29.116+08:00","updated_at":"2018-06-15T14:16:29.116+08:00"},{"id":591624,"file_name":"wall.png","project_id":28905,"asset_id":71535,"created_at":"2018-06-15T14:16:29.123+08:00","updated_at":"2018-06-15T14:16:29.123+08:00"},{"id":591625,"file_name":"grass.png","project_id":28905,"asset_id":71536,"created_at":"2018-06-15T14:16:29.129+08:00","updated_at":"2018-06-15T14:16:29.129+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦