{"id":319048,"student_id":3469,"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 \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) {\n newGrid[x][y] = false;\n }\n } else {\n if (c == 3) {\n newGrid[x][y] = true;\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]) count++;\n if (grid[x+1] \u0026\u0026 grid[x+1][y-1]) count++;\n if (grid[x] \u0026\u0026 grid[x][y+1]) count++;\n if (grid[x] \u0026\u0026 grid[x][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]) count++;\n if (grid[x-1] \u0026\u0026 grid[x-1][y-1]) count++;\n \n\n return count;\n}\n","created_at":"2021-11-27T14:02:35.734+08:00","updated_at":"2022-07-01T21:03:53.095+08:00","name":"生命遊戲(預設版) 副本","language":"javascript","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/319048/0719e995d0b3e83051a06779387986e2.jpg"},"parent_id":183396,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":87,"hashid":"p93sk5qq2","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":6614484,"file_name":"earth.png","project_id":319048,"asset_id":251690,"created_at":"2021-11-27T14:02:35.739+08:00","updated_at":"2021-11-27T14:02:35.739+08:00"},{"id":6614485,"file_name":"space_bg.jpg","project_id":319048,"asset_id":251691,"created_at":"2021-11-27T14:02:35.740+08:00","updated_at":"2021-11-27T14:02:35.740+08:00"},{"id":6614486,"file_name":"koding.png","project_id":319048,"asset_id":251692,"created_at":"2021-11-27T14:02:35.741+08:00","updated_at":"2021-11-27T14:02:35.741+08:00"},{"id":6614487,"file_name":"Gymnopedie_No_1.mp3","project_id":319048,"asset_id":251693,"created_at":"2021-11-27T14:02:35.742+08:00","updated_at":"2021-11-27T14:02:35.742+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦