{"id":1023886,"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\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)\nhint.move_to(270, 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 is_start = True\n \n if key.right == True and head.direction != 270:\n next_direction = 90\n is_start = True\n \n if key.down == True and head.direction != 0:\n next_direction = 180\n is_start = True\n \n if key.left == True and head.direction != 90:\n next_direction = 270\n is_start = True\n \n hint.hidden = is_start\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 and is_start == True:\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 if head.x \u003e 1200:\n head.x = head.x - 1200\n \n if head.x \u003c 0:\n head.x = head.x + 1200\n \n if head.y \u003e 900:\n head.y = head.y - 900\n \n if head.y \u003c 0:\n head.y = head.y + 900\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:17.649+08:00","updated_at":"2025-05-29T12:25:10.252+08:00","name":"11_B_C_貪吃蛇_綜合練習_【講解】等待開始與示意圖 副本","language":"python","screenshot":{"url":null},"parent_id":1012129,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":81,"hashid":"4y3s99586","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":38687012,"file_name":"bg_grid.jpg","project_id":1023886,"asset_id":251902,"created_at":"2025-05-29T12:24:17.655+08:00","updated_at":"2025-05-29T12:24:17.655+08:00"},{"id":38687013,"file_name":"bg.jpg","project_id":1023886,"asset_id":251903,"created_at":"2025-05-29T12:24:17.656+08:00","updated_at":"2025-05-29T12:24:17.656+08:00"},{"id":38687014,"file_name":"body_left.png","project_id":1023886,"asset_id":251904,"created_at":"2025-05-29T12:24:17.657+08:00","updated_at":"2025-05-29T12:24:17.657+08:00"},{"id":38687015,"file_name":"body.png","project_id":1023886,"asset_id":251905,"created_at":"2025-05-29T12:24:17.658+08:00","updated_at":"2025-05-29T12:24:17.658+08:00"},{"id":38687016,"file_name":"apple.png","project_id":1023886,"asset_id":251906,"created_at":"2025-05-29T12:24:17.659+08:00","updated_at":"2025-05-29T12:24:17.659+08:00"},{"id":38687017,"file_name":"gameover.png","project_id":1023886,"asset_id":251907,"created_at":"2025-05-29T12:24:17.660+08:00","updated_at":"2025-05-29T12:24:17.660+08:00"},{"id":38687018,"file_name":"head.png","project_id":1023886,"asset_id":251908,"created_at":"2025-05-29T12:24:17.661+08:00","updated_at":"2025-05-29T12:24:17.661+08:00"},{"id":38687019,"file_name":"hint.png","project_id":1023886,"asset_id":251909,"created_at":"2025-05-29T12:24:17.662+08:00","updated_at":"2025-05-29T12:24:17.662+08:00"},{"id":38687020,"file_name":"tail.png","project_id":1023886,"asset_id":251910,"created_at":"2025-05-29T12:24:17.663+08:00","updated_at":"2025-05-29T12:24:17.663+08:00"},{"id":38687021,"file_name":"orange.png","project_id":1023886,"asset_id":251911,"created_at":"2025-05-29T12:24:17.664+08:00","updated_at":"2025-05-29T12:24:17.664+08:00"},{"id":38687022,"file_name":"bling.ogg","project_id":1023886,"asset_id":251912,"created_at":"2025-05-29T12:24:17.665+08:00","updated_at":"2025-05-29T12:24:17.665+08:00"},{"id":38687023,"file_name":"bgm.mp3","project_id":1023886,"asset_id":251913,"created_at":"2025-05-29T12:24:17.666+08:00","updated_at":"2025-05-29T12:24:17.666+08:00"},{"id":38687024,"file_name":"body_right.png","project_id":1023886,"asset_id":251914,"created_at":"2025-05-29T12:24:17.667+08:00","updated_at":"2025-05-29T12:24:17.667+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
繁中
简中
English
日本語
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦