{"id":1023883,"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 clock = clock + 1\n\n if clock % 10 == 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:10.074+08:00","updated_at":"2025-05-29T12:24:52.339+08:00","name":"11_A_G_貪吃蛇_正課_【講解】遊戲結束 副本","language":"python","screenshot":{"url":null},"parent_id":1012125,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":75,"hashid":"gk4s552vm","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":38686973,"file_name":"bg_grid.jpg","project_id":1023883,"asset_id":251902,"created_at":"2025-05-29T12:24:10.079+08:00","updated_at":"2025-05-29T12:24:10.079+08:00"},{"id":38686974,"file_name":"bg.jpg","project_id":1023883,"asset_id":251903,"created_at":"2025-05-29T12:24:10.081+08:00","updated_at":"2025-05-29T12:24:10.081+08:00"},{"id":38686975,"file_name":"body_left.png","project_id":1023883,"asset_id":251904,"created_at":"2025-05-29T12:24:10.082+08:00","updated_at":"2025-05-29T12:24:10.082+08:00"},{"id":38686976,"file_name":"body.png","project_id":1023883,"asset_id":251905,"created_at":"2025-05-29T12:24:10.083+08:00","updated_at":"2025-05-29T12:24:10.083+08:00"},{"id":38686977,"file_name":"apple.png","project_id":1023883,"asset_id":251906,"created_at":"2025-05-29T12:24:10.084+08:00","updated_at":"2025-05-29T12:24:10.084+08:00"},{"id":38686978,"file_name":"gameover.png","project_id":1023883,"asset_id":251907,"created_at":"2025-05-29T12:24:10.085+08:00","updated_at":"2025-05-29T12:24:10.085+08:00"},{"id":38686979,"file_name":"head.png","project_id":1023883,"asset_id":251908,"created_at":"2025-05-29T12:24:10.086+08:00","updated_at":"2025-05-29T12:24:10.086+08:00"},{"id":38686980,"file_name":"hint.png","project_id":1023883,"asset_id":251909,"created_at":"2025-05-29T12:24:10.087+08:00","updated_at":"2025-05-29T12:24:10.087+08:00"},{"id":38686981,"file_name":"tail.png","project_id":1023883,"asset_id":251910,"created_at":"2025-05-29T12:24:10.088+08:00","updated_at":"2025-05-29T12:24:10.088+08:00"},{"id":38686982,"file_name":"orange.png","project_id":1023883,"asset_id":251911,"created_at":"2025-05-29T12:24:10.089+08:00","updated_at":"2025-05-29T12:24:10.089+08:00"},{"id":38686983,"file_name":"bling.ogg","project_id":1023883,"asset_id":251912,"created_at":"2025-05-29T12:24:10.089+08:00","updated_at":"2025-05-29T12:24:10.089+08:00"},{"id":38686984,"file_name":"bgm.mp3","project_id":1023883,"asset_id":251913,"created_at":"2025-05-29T12:24:10.090+08:00","updated_at":"2025-05-29T12:24:10.090+08:00"},{"id":38686985,"file_name":"body_right.png","project_id":1023883,"asset_id":251914,"created_at":"2025-05-29T12:24:10.091+08:00","updated_at":"2025-05-29T12:24:10.091+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
繁中
简中
English
日本語
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦