{"id":165480,"student_id":10,"content":"var active = false; //是否活躍\nvar clock = 0; //計數器\nvar grid = []; //存放細胞狀態\n\n//初始化二維陣列\nfor (var x = -1; x \u003c 32; x++) {\n grid[x] = [];\n for (var y = -1; y \u003c 24; y++) {\n grid[x][y] = false;\n grid[x][y] = Math.random() \u003e 0.5; //隨機產生細胞\n }\n}\n\n//點擊格子設定顏色\non('click', function () {\n var x = Math.floor(cursor.x/20);\n var y = Math.floor(cursor.y/20);\n grid[x][y] = !grid[x][y];\n});\n\n//「按一次」空白鍵更新一回合\n//「按住」空白按鍵不斷更新回合\non('keydown', 'space', update);\n\n//將二維陣列繪製在遊戲場景上\nforever(function () {\n for (var x = 0; x \u003c 32; x++) {\n for (var y = 0; y \u003c 24; y++) {\n pen.color = '#555';\n pen.fillColor = grid[x][y] ? 'white': 'black';\n pen.drawRect(x*20, y*20, 20, 20);\n // var c = countCells(x, y);\n // drawText(c, x*20, y*20, '#555');\n }\n }\n});\n\n//更新細胞狀態\nfunction update () {\n var newGrid = [];\n for (var x = 0; x \u003c 32; x++) {\n newGrid[x] = [];\n for (var y = 0; y \u003c 24; y++) {\n newGrid[x][y] = grid[x][y];\n \n var c = countCells(x, y);\n if (grid[x][y] == true) { //如果此格子細胞是活著\n if (c \u003c 2 || c \u003e 3) newGrid[x][y] = false;\n } else {\n if (c == 3) newGrid[x][y] = true;\n }\n }\n }\n grid = newGrid;\n};\n\n//計算 x, y 格子周圍存活的細胞個數\nfunction countCells (x, y) {\n var count = 0;\n if (grid[x-1] \u0026\u0026 grid[x-1][y-1]) count++;\n if (grid[x+0] \u0026\u0026 grid[x+0][y-1]) count++;\n if (grid[x+1] \u0026\u0026 grid[x+1][y-1]) count++;\n if (grid[x-1] \u0026\u0026 grid[x-1][y+0]) count++;\n if (grid[x+1] \u0026\u0026 grid[x+1][y+0]) count++;\n if (grid[x-1] \u0026\u0026 grid[x-1][y+1]) count++;\n if (grid[x+0] \u0026\u0026 grid[x+0][y+1]) count++;\n if (grid[x+1] \u0026\u0026 grid[x+1][y+1]) count++;\n return count;\n}\n","created_at":"2020-07-16T10:29:07.803+08:00","updated_at":"2020-08-04T11:56:03.999+08:00","name":"生命遊戲(預設版)","language":"javascript","screenshot":{"url":"https://cdn5.koding.school/uploads/project/screenshot/165480/21e6626c27f35d2e4691bf8cdc301638.jpg"},"parent_id":2,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":311,"hashid":"jzms52ry","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2876737,"file_name":"Gymnopedie_No_1.mp3","project_id":165480,"asset_id":182919,"created_at":"2020-07-16T10:29:07.809+08:00","updated_at":"2020-07-16T10:29:07.809+08:00"},{"id":2876738,"file_name":"koding.png","project_id":165480,"asset_id":182918,"created_at":"2020-07-16T10:29:07.810+08:00","updated_at":"2020-07-16T10:29:07.810+08:00"},{"id":2876739,"file_name":"space_bg.jpg","project_id":165480,"asset_id":182917,"created_at":"2020-07-16T10:29:07.811+08:00","updated_at":"2020-07-16T10:29:07.811+08:00"},{"id":2876740,"file_name":"earth.png","project_id":165480,"asset_id":182916,"created_at":"2020-07-16T10:29:07.811+08:00","updated_at":"2020-07-16T10:29:07.811+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦