{"id":1024400,"student_id":3276,"content":"from game import *\nfrom random import *\n\nbg = create_sprite('bg.png') #背景圖\nrules = create_sprite('rules.png') #遊戲規則\nresult = create_sprite(['end_' + str(i) + '.png' for i in range(13)]) #結果圖\nresult.hidden = True #預設隱藏\nrules.layer = result.layer = 1\ncreate_sound('bgm.mp3', False) #背景音樂\n\narr = [] #存放 16 個方塊角色\nimgs = [str(i) + '.png' for i in range(12)] #方塊角色的造型圖\n\nfor y in range(4):\n for x in range(4):\n b = create_sprite(imgs)\n b.x = 180 * x + 330\n b.y = 180 * y + 180\n arr.append(b)\n\narr[0].costume_id = 1\narr[2].costume_id = 1\n\ndef add():\n empty = []\n for b in arr:\n if b.costume_id == 0: empty.append(b)\n if len(empty) \u003e 0: #如果還有空的格子\n rand = randrange(len(empty)) #產生隨機數\n empty[rand].costume_id = randint(1, 2) #隨機挑選一個方塊設定造型\n empty[rand].scale = 0.1 #預設縮小\n else: #如果沒有空格子就結束遊戲\n gameover()\n create_sound('hit.mp3')\n \n idx = max([b.costume_id for b in arr])\n if idx \u003e result.costume_id:\n result.costume_id = idx\n create_sound('rise.mp3')\n\ndef loop():\n for b in arr + [bg]:\n if bg.x \u003e 600: b.x -= 5\n if bg.x \u003c 600: b.x += 5\n if bg.y \u003e 450: b.y -= 5\n if bg.y \u003c 450: b.y += 5\n if b.scale \u003c 1: b.scale += 0.05\n\n# 移動一行 4 個方塊\n# 由 a -\u003e b -\u003e c -\u003e d 方向移動\ndef move(a, b, c, d):\n # 如果 b 方塊為空,前一個方塊向右移動\n if b.costume_id == 0:\n b.costume_id = a.costume_id\n a.costume_id = 0\n \n # 如果 c 方塊為空,前兩個方塊向右移動\n if c.costume_id == 0:\n c.costume_id = b.costume_id\n b.costume_id = a.costume_id\n a.costume_id = 0\n \n # 如果 d 方塊為空,前三個方塊向右移動\n if d.costume_id == 0:\n d.costume_id = c.costume_id\n c.costume_id = b.costume_id\n b.costume_id = a.costume_id\n a.costume_id = 0 \n \n \n # 如果 c、d 方塊一樣就合併,並讓 a、b 向右移動\n if c.costume_id == d.costume_id and c.costume_id != 0:\n d.costume_id += 1\n c.costume_id = b.costume_id\n b.costume_id = a.costume_id\n a.costume_id = 0\n \n # 如果 b、c 方塊一樣就合併,並讓 a 向右移動\n if b.costume_id == c.costume_id and b.costume_id != 0:\n c.costume_id += 1\n b.costume_id = a.costume_id\n a.costume_id = 0\n \n # 如果 a、b 方塊一樣就合併\n if a.costume_id == b.costume_id and a.costume_id != 0:\n b.costume_id += 1\n a.costume_id = 0\n\n# 向右移動\ndef move_right():\n move(arr[0], arr[1], arr[2], arr[3])\n move(arr[4], arr[5], arr[6], arr[7])\n move(arr[8], arr[9], arr[10], arr[11])\n move(arr[12], arr[13], arr[14], arr[15])\n add()\n\n# 向左移動\ndef move_left():\n move(arr[3], arr[2], arr[1], arr[0])\n move(arr[7], arr[6], arr[5], arr[4])\n move(arr[11], arr[10], arr[9], arr[8])\n move(arr[15], arr[14], arr[13], arr[12]) \n add()\n\n# 向上移動\ndef move_up():\n move(arr[12], arr[8], arr[4], arr[0])\n move(arr[13], arr[9], arr[5], arr[1])\n move(arr[14], arr[10], arr[6], arr[2])\n move(arr[15], arr[11], arr[7], arr[3]) \n add()\n\n# 向下移動\ndef move_down():\n move(arr[0], arr[4], arr[8], arr[12])\n move(arr[1], arr[5], arr[9], arr[13])\n move(arr[2], arr[6], arr[10], arr[14])\n move(arr[3], arr[7], arr[11], arr[15]) \n add()\n\n# 遊戲開始\ndef gamestart():\n rules.hidden = True\n\n# 遊戲結束\ndef gameover():\n result.hidden = False\n stop()\n\non('keydown', 'right', move_right) #向右移動\non('keydown', 'left', move_left) #向左移動\non('keydown', 'up', move_up) #向上移動\non('keydown', 'down', move_down) #向下移動\nrules.on('click', gamestart) #點擊遊戲說明開始遊戲\nforever(loop)\n\n","created_at":"2025-06-01T10:00:22.466+08:00","updated_at":"2025-06-01T10:34:58.822+08:00","name":"熱量大作戰(預設版) 副本","language":"python","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/1024400/1a2dbb1eb49aef242f3884647de4a53b.jpg"},"parent_id":869728,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":23,"hashid":"6rpsdd6pm","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":38699940,"file_name":"end_1.png","project_id":1024400,"asset_id":786358,"created_at":"2025-06-01T10:00:22.473+08:00","updated_at":"2025-06-01T10:00:22.473+08:00"},{"id":38699941,"file_name":"end_12.png","project_id":1024400,"asset_id":786359,"created_at":"2025-06-01T10:00:22.474+08:00","updated_at":"2025-06-01T10:00:22.474+08:00"},{"id":38699942,"file_name":"rules.png","project_id":1024400,"asset_id":786360,"created_at":"2025-06-01T10:00:22.475+08:00","updated_at":"2025-06-01T10:00:22.475+08:00"},{"id":38699943,"file_name":"12.png","project_id":1024400,"asset_id":786361,"created_at":"2025-06-01T10:00:22.477+08:00","updated_at":"2025-06-01T10:00:22.477+08:00"},{"id":38699944,"file_name":"2.png","project_id":1024400,"asset_id":786362,"created_at":"2025-06-01T10:00:22.478+08:00","updated_at":"2025-06-01T10:00:22.478+08:00"},{"id":38699945,"file_name":"3.png","project_id":1024400,"asset_id":786363,"created_at":"2025-06-01T10:00:22.479+08:00","updated_at":"2025-06-01T10:00:22.479+08:00"},{"id":38699946,"file_name":"end_6.png","project_id":1024400,"asset_id":786364,"created_at":"2025-06-01T10:00:22.480+08:00","updated_at":"2025-06-01T10:00:22.480+08:00"},{"id":38699947,"file_name":"end_7.png","project_id":1024400,"asset_id":786365,"created_at":"2025-06-01T10:00:22.481+08:00","updated_at":"2025-06-01T10:00:22.481+08:00"},{"id":38699948,"file_name":"0.png","project_id":1024400,"asset_id":786366,"created_at":"2025-06-01T10:00:22.482+08:00","updated_at":"2025-06-01T10:00:22.482+08:00"},{"id":38699949,"file_name":"1.png","project_id":1024400,"asset_id":786367,"created_at":"2025-06-01T10:00:22.483+08:00","updated_at":"2025-06-01T10:00:22.483+08:00"},{"id":38699950,"file_name":"10.png","project_id":1024400,"asset_id":786368,"created_at":"2025-06-01T10:00:22.484+08:00","updated_at":"2025-06-01T10:00:22.484+08:00"},{"id":38699951,"file_name":"11.png","project_id":1024400,"asset_id":786369,"created_at":"2025-06-01T10:00:22.485+08:00","updated_at":"2025-06-01T10:00:22.485+08:00"},{"id":38699952,"file_name":"bg.png","project_id":1024400,"asset_id":786370,"created_at":"2025-06-01T10:00:22.487+08:00","updated_at":"2025-06-01T10:00:22.487+08:00"},{"id":38699953,"file_name":"end_2.png","project_id":1024400,"asset_id":786371,"created_at":"2025-06-01T10:00:22.488+08:00","updated_at":"2025-06-01T10:00:22.488+08:00"},{"id":38699954,"file_name":"end_3.png","project_id":1024400,"asset_id":786372,"created_at":"2025-06-01T10:00:22.489+08:00","updated_at":"2025-06-01T10:00:22.489+08:00"},{"id":38699955,"file_name":"end_4.png","project_id":1024400,"asset_id":786373,"created_at":"2025-06-01T10:00:22.490+08:00","updated_at":"2025-06-01T10:00:22.490+08:00"},{"id":38699956,"file_name":"end_5.png","project_id":1024400,"asset_id":786374,"created_at":"2025-06-01T10:00:22.491+08:00","updated_at":"2025-06-01T10:00:22.491+08:00"},{"id":38699957,"file_name":"4.png","project_id":1024400,"asset_id":786375,"created_at":"2025-06-01T10:00:22.492+08:00","updated_at":"2025-06-01T10:00:22.492+08:00"},{"id":38699958,"file_name":"5.png","project_id":1024400,"asset_id":786376,"created_at":"2025-06-01T10:00:22.493+08:00","updated_at":"2025-06-01T10:00:22.493+08:00"},{"id":38699959,"file_name":"6.png","project_id":1024400,"asset_id":786377,"created_at":"2025-06-01T10:00:22.494+08:00","updated_at":"2025-06-01T10:00:22.494+08:00"},{"id":38699960,"file_name":"7.png","project_id":1024400,"asset_id":786378,"created_at":"2025-06-01T10:00:22.495+08:00","updated_at":"2025-06-01T10:00:22.495+08:00"},{"id":38699961,"file_name":"bgm.mp3","project_id":1024400,"asset_id":786379,"created_at":"2025-06-01T10:00:22.497+08:00","updated_at":"2025-06-01T10:00:22.497+08:00"},{"id":38699962,"file_name":"rise.mp3","project_id":1024400,"asset_id":786380,"created_at":"2025-06-01T10:00:22.498+08:00","updated_at":"2025-06-01T10:00:22.498+08:00"},{"id":38699963,"file_name":"end_10.png","project_id":1024400,"asset_id":786381,"created_at":"2025-06-01T10:00:22.499+08:00","updated_at":"2025-06-01T10:00:22.499+08:00"},{"id":38699964,"file_name":"end_11.png","project_id":1024400,"asset_id":786382,"created_at":"2025-06-01T10:00:22.500+08:00","updated_at":"2025-06-01T10:00:22.500+08:00"},{"id":38699965,"file_name":"end_8.png","project_id":1024400,"asset_id":786383,"created_at":"2025-06-01T10:00:22.501+08:00","updated_at":"2025-06-01T10:00:22.501+08:00"},{"id":38699966,"file_name":"end_9.png","project_id":1024400,"asset_id":786384,"created_at":"2025-06-01T10:00:22.502+08:00","updated_at":"2025-06-01T10:00:22.502+08:00"},{"id":38699967,"file_name":"hit.mp3","project_id":1024400,"asset_id":786385,"created_at":"2025-06-01T10:00:22.503+08:00","updated_at":"2025-06-01T10:00:22.503+08:00"},{"id":38699968,"file_name":"8.png","project_id":1024400,"asset_id":786386,"created_at":"2025-06-01T10:00:22.505+08:00","updated_at":"2025-06-01T10:00:22.505+08:00"},{"id":38699969,"file_name":"9.png","project_id":1024400,"asset_id":786387,"created_at":"2025-06-01T10:00:22.506+08:00","updated_at":"2025-06-01T10:00:22.506+08:00"},{"id":38699970,"file_name":"gameover.mp3","project_id":1024400,"asset_id":786388,"created_at":"2025-06-01T10:00:22.507+08:00","updated_at":"2025-06-01T10:00:22.507+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
繁中
简中
English
日本語
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦