{"id":48552,"student_id":1440,"content":"//初始化\nvar difficulty = prompt(\"難度要多大\")\nvar swith = false\nvar complete = 0\nvar move = true\nvar end_x = 0\nvar end_y = 0\nvar time = 0\nvar map = []\nvar x = 0\nvar y = 0\nvar player_name=prompt(\"玩家名稱(用於儲存遊戲)\")\nvar player_profile = DB.table('player_profile')\n\nplayer_profile.find({}, function(data) {\n for (var i = 1; i \u003c data.length; i++) {\n player_profile.insert({\n player_name: player_name,\n map:map\n })\n }\n})\n\n//創造空白地圖\nfor (var i = 0; i \u003c 640/lattice; i++) {\n map.push([])\n for (var j = 0; j \u003c 480/lattice; j++) {\n map[i].push({\n x: 0,\n y: 0,\n top: false,\n bottom: false,\n right: false,\n left: false,\n color: \"white\"\n })\n }\n}\n\n//去除不完整的方塊\nfor (var i = 0; i \u003c map.length; i++) {\n for (var j = 0; j \u003c map[i].length; j++) {\n if (i*lattice+lattice \u003e 640 || j*lattice+lattice \u003e 480) {\n map[i][j].color = \"black\"\n }\n }\n}\n\n//創造地圖\ncreate()\n\n//主程式\nforever(function() {\n if (x == end_x \u0026\u0026 y == end_y) {\n pen.color = \"white\"\n pen.fillColor = \"white\"\n if (640%lattice == 0 \u0026\u0026 480%lattice == 0) {\n print(\"You End The Game\", (map[map.length-1][0].x+lattice)/2-50, (map[0][map[0].length-1].y+lattice)/2)\n pen.drawRect((map[map.length-1][0].x+lattice)/2-60, (map[0][map[0].length-1].y+lattice)/2-10, 150, 40)\n } else {\n print(\"You End The Game\", (map[map.length-2][0].x+lattice)/2-50, (map[0][map[0].length-2].y+lattice)/2)\n }\n }\n if (swith) {\n draw_map()\n draw_player()\n if (move) {\n map[x][y].color = \"lightblue\"\n if (key.up || key.w) {\n if (y \u003e 0) {\n if (map[x][y].top \u0026\u0026 map[x][y-1].color != \"black\") {\n map[x][y].color = \"lightblue\"\n y--\n move = false\n }\n }\n }\n if (key.down || key.s) {\n if (y \u003c map[0].length) {\n if (map[x][y].bottom \u0026\u0026 map[x][y+1].color != \"black\") {\n map[x][y].color = \"lightblue\"\n y++\n move = false\n }\n }\n }\n if (key.left || key.a) {\n if (x \u003e 0) {\n if (map[x][y].left \u0026\u0026 map[x-1][y].color != \"black\") {\n map[x][y].color = \"lightblue\"\n x--\n move = false\n }\n }\n }\n if (key.right || key.d) {\n if (x \u003c map.length) {\n if (map[x][y].right \u0026\u0026 map[x+1][y].color != \"black\") {\n map[x][y].color = \"lightblue\"\n x++\n move = false\n }\n }\n }\n } else {\n setTimeout(function() {\n move = true\n }, 100);\n }\n } else {\n print(\"Loading \"+load()+\"%\", 640/2, 480/2)\n }\n})\n\n//取得可以挖路的方向\nfunction getNeighbors (x, y) {\n var list = []\n if (!map[x][y].top \u0026\u0026 y \u003e 0 \u0026\u0026 map[x][y-1].color == \"white\") {\n list.push(\"top\")\n }\n if (!map[x][y].bottom \u0026\u0026 y \u003c map[0].length-1 \u0026\u0026 map[x][y+1].color == \"white\") {\n list.push(\"bottom\")\n }\n if (!map[x][y].left \u0026\u0026 x \u003e 0 \u0026\u0026 map[x-1][y].color == \"white\") {\n list.push(\"left\")\n }\n if (!map[x][y].right \u0026\u0026 x \u003c map.length-1 \u0026\u0026 map[x+1][y].color == \"white\") {\n list.push(\"right\")\n }\n return list[Math.floor(Math.random()*list.length)]\n}\n\n//創造地圖的移動指令\nfunction move_top() {\n map[x][y].top = true\n y--\n map[x][y].bottom = true\n}\n\nfunction move_bottom() {\n map[x][y].bottom = true\n y++\n map[x][y].top = true\n}\n\nfunction move_left() {\n map[x][y].left = true\n x--\n map[x][y].right = true\n}\n\nfunction move_right() {\n map[x][y].right = true\n x++\n map[x][y].left = true\n}\n\n//載入百分比計算\nfunction load() {\n complete = 0\n for (var i = 0; i \u003c map.length; i++) {\n for (var j = 0; j \u003c map[i].length; j++) {\n if (map[i][j].color == \"yellow\" || map[i][j].color == \"black\") {\n complete++\n }\n }\n }\n return Math.floor([(complete*100)/(map.length*map[0].length)]*100)/100\n}\n\n//創造地圖\nfunction create() {\n map[x][y].color = \"lightblue\"\n random = getNeighbors (x, y)\n if (random == \"right\") {\n move_right()\n }\n if (random == \"left\") {\n move_left()\n }\n if (random == \"top\") {\n move_top()\n }\n if (random == \"bottom\") {\n move_bottom()\n }\n if (random == undefined) {\n map[x][y].color = \"yellow\"\n if (map[x][y].right \u0026\u0026 map[x+1][y].color == \"lightblue\") {\n x++\n } else if (map[x][y].left \u0026\u0026 map[x-1][y].color == \"lightblue\") {\n x--\n } else if (map[x][y].top \u0026\u0026 map[x][y-1].color == \"lightblue\") {\n y--\n } else if (map[x][y].bottom \u0026\u0026 map[x][y+1].color == \"lightblue\") {\n y++\n }\n }\n\n if (load() == 100) {\n swith = true\n for (var i = 0; i \u003c map.length; i++) {\n for (var j = 0; j \u003c map[i].length; j++) {\n if (map[i][j].color != \"black\") {\n map[i][j].color = \"white\"\n }\n }\n }\n map[x][y].color = \"lightblue\"\n while (end_x \u003c map.length/2 || end_y \u003c map[0].length/2) {\n if (640%lattice == 0 \u0026\u0026 480%lattice == 0) {\n end_x = Math.floor(Math.random()*map.length)\n end_y = Math.floor(Math.random()*map[0].length)\n } else {\n end_x = Math.floor(Math.random()*(map.length-1))\n end_y = Math.floor(Math.random()*(map[0].length-1))\n }\n\n }\n map[end_x][end_y].color = \"green\"\n } else {\n var t = setTimeout(create)\n }\n}\n\n//畫玩家\nfunction draw_player() {\n pen.color = \"red\"\n pen.fillColor = \"red\"\n pen.drawRect(x*lattice+0.5, y*lattice+0.5, lattice-2, lattice-2)\n}\n\n//畫地圖\nfunction draw_map() {\n //noprotect\n for (var i = 0; i \u003c map.length; i++) {\n for (var j = 0; j \u003c map[i].length; j++) {\n map[i][j].x = i*lattice\n map[i][j].y = j*lattice\n pen.color = map[i][j].color\n pen.fillColor = map[i][j].color\n pen.drawRect(map[i][j].x, map[i][j].y, lattice, lattice)\n pen.color = \"black\"\n pen.fillColor = \"black\"\n if (!map[i][j].top) {\n pen.drawRect(map[i][j].x, map[i][j].y, lattice, 0.1)\n }\n if (!map[i][j].bottom) {\n pen.drawRect(map[i][j].x, map[i][j].y+lattice, lattice, 0.1)\n }\n if (!map[i][j].left) {\n pen.drawRect(map[i][j].x, map[i][j].y, 0.1, lattice)\n }\n if (!map[i][j].right) {\n pen.drawRect(map[i][j].x+lattice, map[i][j].y, 0.1, lattice)\n }\n }\n }\n}","created_at":"2018-11-10T21:41:29.361+08:00","updated_at":"2019-10-31T12:40:25.117+08:00","name":"走迷宮","language":"javascript","screenshot":{"url":null},"parent_id":2,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":96,"hashid":"zpes33rd","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
到這台電腦