{"id":219927,"student_id":3463,"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 = 'black'\n } else {\n pen.fillColor = 'white'\n }\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\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\u003c2||c\u003e3) newgrid[x][y] = false\n } else {\n if(c==3) if (c==3) newgrid[x][y] = true\n }\n }\n }\ngrid = newgrid\n\n\n\n\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+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] \u0026\u0026 grid[x][y-1]) count++\n if (grid[x-1] \u0026\u0026 grid[x-1][y]) count++\n if (grid[x] \u0026\u0026 grid[x][y+1]) count++\n if (grid[x+1] \u0026\u0026 grid[x+1][y]) count++\n return count\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n}","created_at":"2021-01-16T14:35:11.900+08:00","updated_at":"2021-01-16T15:32:27.113+08:00","name":"生命遊戲(預設版) 副本","language":"javascript","screenshot":{"url":"https://cdn6.koding.school/uploads/project/screenshot/219927/1b37887f5cda6d82cf19c30f0930f8e0.jpg"},"parent_id":183396,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":101,"hashid":"yeysvqjdj","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3899660,"file_name":"earth.png","project_id":219927,"asset_id":251690,"created_at":"2021-01-16T14:35:11.905+08:00","updated_at":"2021-01-16T14:35:11.905+08:00"},{"id":3899661,"file_name":"space_bg.jpg","project_id":219927,"asset_id":251691,"created_at":"2021-01-16T14:35:11.906+08:00","updated_at":"2021-01-16T14:35:11.906+08:00"},{"id":3899662,"file_name":"koding.png","project_id":219927,"asset_id":251692,"created_at":"2021-01-16T14:35:11.907+08:00","updated_at":"2021-01-16T14:35:11.907+08:00"},{"id":3899663,"file_name":"Gymnopedie_No_1.mp3","project_id":219927,"asset_id":251693,"created_at":"2021-01-16T14:35:11.908+08:00","updated_at":"2021-01-16T14:35:11.908+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦