{"id":27197,"student_id":2591,"content":"setBackdrop(\"#ad9d8f\");\n\nlet grid = [\n [0, 0, 0, 0],\n [0, 0, 0, 0],\n [0, 0, 0, 0],\n [0, 0, 0, 0]\n];\n\nforever(function(){\n\n let points = 0;\n\n for (let x=0; x\u003c4; x++) {\n for (let y=0; y\u003c4; y++) {\n\n points += grid[x][y];\n\n pen.size = 0;\n\n if (grid[x][y] === 0) pen.fillColor = \"#CDBFB6\";\n if (grid[x][y] === 2) pen.fillColor = \"#EEE4DA\";\n if (grid[x][y] === 4) pen.fillColor = \"#ECE0C8\";\n if (grid[x][y] === 8) pen.fillColor = \"#F2B179\";\n if (grid[x][y] === 16) pen.fillColor = \"#F59563\";\n if (grid[x][y] === 32) pen.fillColor = \"#F77B5F\";\n if (grid[x][y] === 64) pen.fillColor = \"#F55E3D\";\n if (grid[x][y] === 128) pen.fillColor = \"#EDCE71\";\n if (grid[x][y] === 256) pen.fillColor = \"#EDCC61\";\n if (grid[x][y] === 512) pen.fillColor = \"#ECC850\";\n if (grid[x][y] === 1024) pen.fillColor = \"#EDC53F\";\n if (grid[x][y] === 2048) pen.fillColor = \"#EEC22E\";\n if (grid[x][y] \u003e 2048) pen.fillColor = \"#3E3B34\";\n\n pen.drawRect(x*105 + 110, y*105 + 35, 100, 100);\n\n if(grid[x][y] !== 0) {\n print(grid[x][y], x*105 + 120, y*105 + 45, '#fff', 30);\n }\n } \n }\n\n print(points);\n});\n\nfunction create () {\n\n let empty = 0;\n for(let c1=0; c1\u003c4; c1++) {\n for(let c2=0; c2\u003c4; c2++) {\n if (grid[c1][c2] === 0) empty++;\n }\n }\n if (empty === 0) return;\n\n let x = Math.floor(Math.random()*4);\n let y = Math.floor(Math.random()*4);\n\n while(grid[x][y] !== 0) {\n x = Math.floor(Math.random()*4);\n y = Math.floor(Math.random()*4);\n }\n\n grid[x][y] = 2;\n}\n\nwhen('keydown', 'up', function () {\n moveAll(0, -1);\n});\nwhen('keydown', 'down', function () {\n moveAll(0, 1);\n});\nwhen('keydown', 'right', function () {\n moveAll(1, 0);\n});\nwhen('keydown', 'left', function () {\n moveAll(-1, 0);\n});\n\nlet protect = 0;\nfunction moveAll (x, y) {\n let isChange = false;\n while (true) {\n let done = true;\n for(let c1=0; c1\u003c4; c1++) {\n for(let c2=0; c2\u003c4; c2++) {\n if (move(c1, c2, x, y)) {\n done = false;\n isChange = true; \n }\n }\n }\n for(let c1=3; c1\u003e=0; c1--) {\n for(let c2=3; c2\u003e=0; c2--) {\n if (move(c1, c2, x, y)) {\n done = false;\n isChange = true; \n }\n }\n }\n if (done) break;\n }\n if (isChange) create();\n}\n\nfunction move (x, y, vx, vy) {\n\n if (grid[x][y] === 0 || x+vx \u003c 0 || x+vx \u003e 3 || y+vy \u003c 0 || y+vy \u003e 3) return false;\n\n if (grid[x + vx][y + vy] === 0) {\n grid[x + vx][y + vy] = grid[x][y];\n grid[x][y] = 0;\n return true;\n }\n if (grid[x + vx][y + vy] == grid[x][y]) {\n grid[x + vx][y + vy] *= 2;\n grid[x][y] = 0;\n return true;\n }\n\n return false;\n}\n\ncreate();","created_at":"2018-04-27T10:13:59.568+08:00","updated_at":"2019-09-16T00:37:50.006+08:00","name":"2048","language":"javascript","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/27197/d2cb08b26e3335d8a671b82d0e41ecdc.jpg"},"parent_id":12677,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":114,"hashid":"4y3sz4yz","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
到這台電腦