{"id":1030669,"student_id":1443,"content":"from game import *\nfrom random import randrange\n\ngrid = [\n [0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n]\n\nclock = 0\n\ndef loop():\n global clock\n clock += 1\n draw() #手動繪製\n if clock % 20 == 0: update() #更新\n render() #繪製方塊\n\ndef draw():\n if cursor.is_down:\n x = cursor.x // 50\n y = cursor.y // 50\n if grid[y][x] == 0: grid[y][x] = 1\n\ndef render():\n for x in range(24):\n for y in range(18):\n colors = ['white', 'black', '#ccc']\n pen.size = 8\n pen.color = '#ccc'\n pen.fillColor = colors[grid[y][x]]\n pen.draw_rect(x * 50, y * 50, 50, 50)\n\ndef update():\n global grid\n next_grid = [row[:] for row in grid] #複製 grid 至 next_grid\n for x in range(24):\n for y in range(18):\n i = 0 #計算周圍有多少的存活細胞\n for xx in range(-1, 2):\n for yy in range(-1, 2):\n if xx == 0 and yy == 0: continue\n cx = (x + xx + 24) % 24\n cy = (y + yy + 18) % 18\n i += grid[cy][cx]\n \n if grid[y][x] == 1 and i \u003c= 1: next_grid[y][x] = 0\n if grid[y][x] == 1 and i \u003e= 4: next_grid[y][x] = 0\n if grid[y][x] == 0 and i == 3: next_grid[y][x] = 1\n grid = next_grid\n \nforever(loop)\n ","created_at":"2025-06-10T16:17:52.711+08:00","updated_at":"2025-06-10T16:37:07.564+08:00","name":"生命遊戲_預設專案 副本","language":"python","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/1030669/c4c1b4fc31318de1ee753da520c3f20d.jpg"},"parent_id":879026,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":31,"hashid":"wdksp335g","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":38875028,"file_name":"cloud.png","project_id":1030669,"asset_id":790084,"created_at":"2025-06-10T16:17:52.717+08:00","updated_at":"2025-06-10T16:17:52.717+08:00"},{"id":38875029,"file_name":"bg.jpg","project_id":1030669,"asset_id":790085,"created_at":"2025-06-10T16:17:52.719+08:00","updated_at":"2025-06-10T16:17:52.719+08:00"},{"id":38875030,"file_name":"calm.mp3","project_id":1030669,"asset_id":790086,"created_at":"2025-06-10T16:17:52.720+08:00","updated_at":"2025-06-10T16:17:52.720+08:00"},{"id":38875031,"file_name":"koding.png","project_id":1030669,"asset_id":790087,"created_at":"2025-06-10T16:17:52.721+08:00","updated_at":"2025-06-10T16:17:52.721+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
繁中
简中
English
日本語
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦