{"id":235333,"student_id":1998,"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 if (grid[x][y] == true) {\n pen.fillColor = 'white'\n } else {\n pen.fillColor = 'black'\n }\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 var c = countCells(x, y)\n if (grid[x][y]) {\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\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-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 return count;\n}","created_at":"2021-03-13T17:03:31.701+08:00","updated_at":"2021-03-13T17:44:40.482+08:00","name":"生命遊戲(預設版) 副本","language":"javascript","screenshot":{"url":"https://cdn5.koding.school/uploads/project/screenshot/235333/e22ec44af0488ddd33c668f459b84091.jpg"},"parent_id":183396,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":41,"hashid":"2pds9pmz5","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":4261620,"file_name":"earth.png","project_id":235333,"asset_id":251690,"created_at":"2021-03-13T17:03:31.709+08:00","updated_at":"2021-03-13T17:03:31.709+08:00"},{"id":4261621,"file_name":"space_bg.jpg","project_id":235333,"asset_id":251691,"created_at":"2021-03-13T17:03:31.711+08:00","updated_at":"2021-03-13T17:03:31.711+08:00"},{"id":4261622,"file_name":"koding.png","project_id":235333,"asset_id":251692,"created_at":"2021-03-13T17:03:31.713+08:00","updated_at":"2021-03-13T17:03:31.713+08:00"},{"id":4261623,"file_name":"Gymnopedie_No_1.mp3","project_id":235333,"asset_id":251693,"created_at":"2021-03-13T17:03:31.714+08:00","updated_at":"2021-03-13T17:03:31.714+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦