{"id":13997,"student_id":888,"content":"var player = createSprite(\"player.png\");\nvar shadow = createSprite(\"shadow.png\");\nvar target = createSprite(\"target.png\");\ntarget.moveTo(630, 470);\ntarget.scale = 0.7;\nshadow.opacity = 0;\nplayer.scale = 0.7;\n\nplayer.from = {x: 0, y: 0}\nplayer.to = {x: 0, y: 0}\nplayer.x = 10;\nplayer.y = 10;\nplayer.nextDirection;\n\nvar status = '';\nvar SIZE = 20;\nvar W = 640/SIZE;\nvar H = 480/SIZE;\nvar grid = [];\nvar groups = [];\n\nfor (var x=0; x\u003cW; x++) {\n grid[x] = [];\n for (var y=0; y\u003cH; y++) {\n grid[x][y] = '1234';\n groups.push([y*W + x]);\n }\n}\n\nfunction merge () {\n\n if (groups.length \u003c= 1) return;\n\n var rand = Math.floor(Math.random()*groups.length);\n var group1 = groups.splice(rand, 1)[0];\n var group2 = [];\n var a, b, direction;\n\n while (true) {\n a = group1[Math.floor(Math.random()*group1.length)];\n b = direction = undefined;\n\n direction = Math.ceil(Math.random()*4);\n\n if (direction == 1) b = a - W;\n if (direction == 2) b = a + 1;\n if (direction == 3) b = a + W;\n if (direction == 4) b = a - 1;\n\n if (group1.includes(b)) continue;\n if (b \u003c 0 || b \u003e W*H-1) continue;\n if (a%W == 0 \u0026\u0026 direction == 4) continue;\n if (a%W == W-1 \u0026\u0026 direction == 2) continue;\n\n var cell1 = grid[a%W][Math.floor(a/W)];\n var cell2 = grid[b%W][Math.floor(b/W)];\n grid[a%W][Math.floor(a/W)] = cell1.replace(direction, '');\n grid[b%W][Math.floor(b/W)] = cell2.replace(direction \u003e 2 ? direction - 2 : direction + 2, '');\n\n break;\n }\n\n for (var i=0; i\u003cgroups.length; i++) {\n if (groups[i].includes(b)) {\n var index = groups.indexOf(groups[i]);\n group2 = groups.splice(index, 1)[0];\n }\n }\n groups.push(group1.concat(group2));\n}\n\nforever(function(){\n\n if (groups.length \u003e 1) {\n for(var i=0; i\u003c4; i++) merge();\n }\n\n if (status == 'gameOver') {\n shadow.opacity -= 0.01;\n if (shadow.opacity \u003c 0) shadow.opacity = 0;\n } else if (shadow.opacity \u003c 1) {\n shadow.opacity += 0.005;\n }\n if (player.from.x == 31 \u0026\u0026 player.from.y == 23) { \n status = 'gameOver'\n }\n shadow.moveTo(player);\n\n for (var x=0; x\u003cgrid.length; x++) {\n for (var y=0; y\u003cgrid[x].length; y++) {\n var cell = grid[x][y];\n if (cell.includes(1)) pen.drawRect(x*SIZE, y*SIZE, SIZE, 2);\n if (cell.includes(2)) pen.drawRect(x*SIZE + SIZE - 2, y*SIZE, 2, SIZE);\n if (cell.includes(3)) pen.drawRect(x*SIZE, y*SIZE + SIZE - 2, SIZE, 2);\n if (cell.includes(4)) pen.drawRect(x*SIZE, y*SIZE, 2, SIZE);\n }\n }\n});\n\nforever(function(){\n\n if (key.up) player.nextDirection = 1;\n if (key.right) player.nextDirection = 2;\n if (key.down) player.nextDirection = 3;\n if (key.left) player.nextDirection = 4;\n\n var x = player.to.x*20 + 10;\n var y = player.to.y*20 + 10;\n\n player.toward(x, y);\n\n if (player.distanceTo(x, y) \u003c 0.5) {\n player.moveTo(x, y);\n player.from = player.to;\n\n if (!grid[player.from.x][player.from.y].includes(player.nextDirection)) {\n if (player.nextDirection == 1) {\n player.to.x = player.from.x;\n player.to.y = player.from.y - 1;\n } \n if (player.nextDirection == 2) {\n player.to.x = player.from.x + 1;\n player.to.y = player.from.y;\n } \n if (player.nextDirection == 3) {\n player.to.x = player.from.x;\n player.to.y = player.from.y + 1;\n } \n if (player.nextDirection == 4) {\n player.to.x = player.from.x - 1;\n player.to.y = player.from.y;\n } \n }\n\n } else {\n player.stepForward(1); \n }\n});","created_at":"2017-03-01T20:52:04.729+08:00","updated_at":"2025-02-22T13:38:51.703+08:00","name":"迷宮","language":"javascript","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/13997/ca11abb84e547a56618473a95c6924f7.jpg"},"parent_id":2,"plugin":"","description":"上、下、左、右按鍵移動\n走到右下角的黃色方塊迷宮出口","note":null,"status":"public","like_student_ids":[4292,4354,4502,4507,4464,7094,8645,9272,9772,9767,9774,18989,10522,26781,12179,16868,11532,12976,15259,17411,31501,11203,32705,29570,39963,39194,35713,43026,26904,55331,41715,43039,49821,22028,54704,42184,53235,55325,41228,37291,58913,62087,40048,41376,73614,64656,68052,69725,62388,50599,39959,51321,82589,50562,54549,77517,36656,54672,48126],"is_featured":true,"views":4062,"hashid":"ej9s2pmr","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":284682,"file_name":"player.png","project_id":13997,"asset_id":34369,"created_at":"2017-10-26T19:14:27.611+08:00","updated_at":"2017-10-26T19:14:27.611+08:00"},{"id":284683,"file_name":"shadow.png","project_id":13997,"asset_id":34370,"created_at":"2017-10-26T19:14:27.613+08:00","updated_at":"2017-10-26T19:14:27.613+08:00"},{"id":284684,"file_name":"target.png","project_id":13997,"asset_id":34371,"created_at":"2017-10-26T19:14:27.614+08:00","updated_at":"2017-10-26T19:14:27.614+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦