{"id":216828,"student_id":10,"content":"from game import *\nimport random\n\nset_backdrop(\"black\")\n\nhead = create_sprite(\"body.png\")\nbody = [create_sprite(\"body.png\")]\nfood = []\n\nhead.x = 50*12 + 25\nhead.y = 50*9 + 25\n\n\nclock = 0\n\ndef loop():\n global clock, body\n \n draw_text(int(clock/60), 10, 10, 'blue', 40)\n \n clock += 1\n if clock % 10 == 0:\n tail = body.pop()\n tail.move_to(head)\n head.step_forward(50)\n body = [tail] + body\n \n for f in food:\n if f.touched(head):\n b = create_sprite(\"body.png\")\n b.move_to(head)\n f.destroy()\n body.append(b)\n \n for b in body:\n if b.touched(head):\n set_backdrop(\"pink\")\n stop()\n \n if clock % 60 == 0:\n f = create_sprite('food.png')\n f.x = random.randrange(0, 24) * 50 + 25\n f.y = random.randrange(0, 18) * 50 + 25\n food.append(f)\n \n \n if key.up and head.direction != 180: head.direction = 0\n if key.right and head.direction != 270: head.direction = 90\n if key.down and head.direction != 0: head.direction = 180\n if key.left and head.direction != 90: head.direction = 270\n \n if head.x \u003c 0 or head.x \u003e 1200 or head.y \u003c 0 or head.y \u003e 900:\n set_backdrop(\"pink\")\n stop()\n \n\ngame.forever(loop) #重複不斷執行","created_at":"2021-01-06T18:11:47.041+08:00","updated_at":"2021-01-06T18:52:15.283+08:00","name":"節食蛇","language":"python","screenshot":{"url":"https://cdn2.koding.school/uploads/project/screenshot/216828/d1df25b2738683732bd80fb77933492e.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":212,"hashid":"meysw6n89","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3819559,"file_name":"body.png","project_id":216828,"asset_id":302835,"created_at":"2021-01-06T18:12:16.860+08:00","updated_at":"2021-01-06T18:12:16.860+08:00"},{"id":3819560,"file_name":"food.png","project_id":216828,"asset_id":302836,"created_at":"2021-01-06T18:12:16.862+08:00","updated_at":"2021-01-06T18:12:16.862+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦