{"id":12677,"student_id":10,"content":"setBackdrop(\"#ad9d8f\");\n\nvar 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 var points = 0;\n\n for (var x=0; x\u003c4; x++) {\n for (var 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 print(grid[x][y], x*105 + 120, y*105 + 45, '#fff', 30);\n } \n }\n\n print(points);\n});\n\nfunction create () {\n\n var empty = 0;\n for(var c1=0; c1\u003c4; c1++) {\n for(var c2=0; c2\u003c4; c2++) {\n if (grid[c1][c2] == 0) empty++;\n }\n }\n if (empty == 0) return\n\n var x = Math.floor(Math.random()*4);\n var y = Math.floor(Math.random()*4);\n\n while(grid[x][y] != 0) {\n var x = Math.floor(Math.random()*4);\n var 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\nvar protect = 0;\nfunction moveAll (x, y) {\n var isChange = false;\n while (true) {\n var done = true;\n for(var c1=0; c1\u003c4; c1++) {\n for(var c2=0; c2\u003c4; c2++) {\n if (move(c1, c2, x, y)) {\n done = false;\n isChange = true; \n }\n }\n }\n for(var c1=3; c1\u003e=0; c1--) {\n for(var 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":"2017-03-01T20:52:04.729+08:00","updated_at":"2021-03-24T16:49:15.865+08:00","name":"2048","language":"javascript","screenshot":{"url":"https://cdn8.koding.school/uploads/project/screenshot/12677/788077781a208b2bf5c46b5722599416.jpg"},"parent_id":2,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[10,2333],"is_featured":true,"views":1139,"hashid":"9ygspg6j","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
到這台電腦