{"id":1023884,"student_id":2589,"content":"import random\nfrom game import (\n set_backdrop,\n create_sprite,\n create_sound,\n draw_text,\n key,\n forever,\n stop\n)\n\nset_backdrop('bg_grid.jpg')\nfood = create_sprite('apple.png', 'orange.png')\nhead = create_sprite('head.png')\nhint = create_sprite('hint.png')\ngame_over = create_sprite('gameover.png')\ntail = create_sprite('body.png', 'body_left.png', 'body_right.png', 'tail.png')\n\ntail.costume_id = 3\n\nfood.layer = 1\nhead.layer = 2\ngame_over.layer = 3\n\ngame_over.hidden = True\nhint.hidden = True\n\nclock = 0\nnext_direction = 90\nbodies = [tail]\nis_start = False\nlevel = 0\n\nfood.move_to(930, 450)\nhead.move_to(270, 450)\ntail.move_to(210, 450)\n\n\n\ndef loop():\n global clock, next_direction, is_start, level, bodies\n\n if key.up == True and head.direction != 180:\n next_direction = 0\n \n if key.right == True and head.direction != 270:\n next_direction = 90\n \n if key.down == True and head.direction != 0:\n next_direction = 180\n \n if key.left == True and head.direction != 90:\n next_direction = 270\n \n level = (len(bodies) - 1) // 5\n if level \u003e 10:\n level = 10\n \n clock = clock + 1\n\n if clock % (15 - level) == 0:\n if head.touched(food) == True:\n food.x = random.randrange(20) * 60 + 30\n food.y = random.randrange(15) * 60 + 30\n \n b = create_sprite('body.png', 'body_left.png', 'body_right.png', 'tail.png')\n b.move_to(head)\n bodies.append(b)\n \n if len(bodies) \u003e 0:\n b = bodies.pop()\n b.move_to(head)\n bodies = [b] + bodies\n update_bodies_costume()\n \n head.direction = next_direction\n head.step_forward(60)\n \n if head.touched(bodies) == True:\n stop()\n game_over.hidden = False\n draw_text(len(bodies) - 1, 550, 430, 'white', 80)\n \n draw_text(len(bodies) - 1, 10, 10, 'white', 40)\n\n\nforever(loop)\n\n\n\ndef update_bodies_costume():\n diff = next_direction - head.direction\n\n if diff == 0:\n bodies[0].costume_id = 0\n \n if diff == -90 or diff == 270:\n bodies[0].costume_id = 1\n \n if diff == 90 or diff == -270:\n bodies[0].costume_id = 2\n \n bodies[0].direction = next_direction\n\n bodies[-1].costume_id = 3\n","created_at":"2025-05-29T12:24:12.367+08:00","updated_at":"2025-05-29T12:25:01.114+08:00","name":"11_B_A_貪吃蛇_綜合練習_【講解】提升速度 副本","language":"python","screenshot":{"url":null},"parent_id":1012127,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":98,"hashid":"882see2rv","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":38686986,"file_name":"bg_grid.jpg","project_id":1023884,"asset_id":251902,"created_at":"2025-05-29T12:24:12.372+08:00","updated_at":"2025-05-29T12:24:12.372+08:00"},{"id":38686987,"file_name":"bg.jpg","project_id":1023884,"asset_id":251903,"created_at":"2025-05-29T12:24:12.374+08:00","updated_at":"2025-05-29T12:24:12.374+08:00"},{"id":38686988,"file_name":"body_left.png","project_id":1023884,"asset_id":251904,"created_at":"2025-05-29T12:24:12.374+08:00","updated_at":"2025-05-29T12:24:12.374+08:00"},{"id":38686989,"file_name":"body.png","project_id":1023884,"asset_id":251905,"created_at":"2025-05-29T12:24:12.375+08:00","updated_at":"2025-05-29T12:24:12.375+08:00"},{"id":38686990,"file_name":"apple.png","project_id":1023884,"asset_id":251906,"created_at":"2025-05-29T12:24:12.376+08:00","updated_at":"2025-05-29T12:24:12.376+08:00"},{"id":38686991,"file_name":"gameover.png","project_id":1023884,"asset_id":251907,"created_at":"2025-05-29T12:24:12.377+08:00","updated_at":"2025-05-29T12:24:12.377+08:00"},{"id":38686992,"file_name":"head.png","project_id":1023884,"asset_id":251908,"created_at":"2025-05-29T12:24:12.378+08:00","updated_at":"2025-05-29T12:24:12.378+08:00"},{"id":38686993,"file_name":"hint.png","project_id":1023884,"asset_id":251909,"created_at":"2025-05-29T12:24:12.379+08:00","updated_at":"2025-05-29T12:24:12.379+08:00"},{"id":38686994,"file_name":"tail.png","project_id":1023884,"asset_id":251910,"created_at":"2025-05-29T12:24:12.380+08:00","updated_at":"2025-05-29T12:24:12.380+08:00"},{"id":38686995,"file_name":"orange.png","project_id":1023884,"asset_id":251911,"created_at":"2025-05-29T12:24:12.381+08:00","updated_at":"2025-05-29T12:24:12.381+08:00"},{"id":38686996,"file_name":"bling.ogg","project_id":1023884,"asset_id":251912,"created_at":"2025-05-29T12:24:12.382+08:00","updated_at":"2025-05-29T12:24:12.382+08:00"},{"id":38686997,"file_name":"bgm.mp3","project_id":1023884,"asset_id":251913,"created_at":"2025-05-29T12:24:12.383+08:00","updated_at":"2025-05-29T12:24:12.383+08:00"},{"id":38686998,"file_name":"body_right.png","project_id":1023884,"asset_id":251914,"created_at":"2025-05-29T12:24:12.384+08:00","updated_at":"2025-05-29T12:24:12.384+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
繁中
简中
English
日本語
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦