{"id":879011,"student_id":10,"content":"from game import *\nfrom random import randrange\n\ngrid = [\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,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n [0,1,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,1,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 % == 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":"2024-11-04T10:30:53.163+08:00","updated_at":"2024-11-04T15:30:46.097+08:00","name":"生命遊戲_預設專案","language":"python","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/879011/c306b9451248212cc7c6b5bb4df8b81a.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":5,"hashid":"yeys4p84d","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":26989644,"file_name":"cloud.png","project_id":879011,"asset_id":302343,"created_at":"2024-11-04T10:30:53.169+08:00","updated_at":"2024-11-04T10:30:53.169+08:00"},{"id":26989645,"file_name":"bg.jpg","project_id":879011,"asset_id":302344,"created_at":"2024-11-04T10:30:53.170+08:00","updated_at":"2024-11-04T10:30:53.170+08:00"},{"id":26989646,"file_name":"calm.mp3","project_id":879011,"asset_id":302345,"created_at":"2024-11-04T10:30:53.172+08:00","updated_at":"2024-11-04T10:30:53.172+08:00"},{"id":26989647,"file_name":"koding.png","project_id":879011,"asset_id":302346,"created_at":"2024-11-04T10:30:53.173+08:00","updated_at":"2024-11-04T10:30:53.173+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦