{"id":890319,"student_id":2589,"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', True) #背景音樂\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\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 \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 # 如果 c、d 方塊一樣就合併,並讓 a、b 向右移動\n if c.costume_id == d.costume_id and c.costume_id \u003e 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 \u003e 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 \u003e 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 for b in arr: b.x += 20\n bg.x += 20\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 for b in arr: b.x -= 20\n bg.x -= 20\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 for b in arr: b.y -= 20\n bg.y -= 20\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 for b in arr: b.y += 20\n bg.y += 20\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)\nadd()\nadd()\n\n","created_at":"2024-11-22T11:08:03.158+08:00","updated_at":"2024-11-22T11:08:18.784+08:00","name":"熱量大作戰(完整版) ","language":"python","screenshot":{"url":null},"parent_id":890317,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":2,"hashid":"gk4s8rpen","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":34613777,"file_name":"end_1.png","project_id":890319,"asset_id":793542,"created_at":"2024-11-22T11:08:03.163+08:00","updated_at":"2024-11-22T11:08:03.163+08:00"},{"id":34613778,"file_name":"end_12.png","project_id":890319,"asset_id":793543,"created_at":"2024-11-22T11:08:03.165+08:00","updated_at":"2024-11-22T11:08:03.165+08:00"},{"id":34613779,"file_name":"rules.png","project_id":890319,"asset_id":793544,"created_at":"2024-11-22T11:08:03.166+08:00","updated_at":"2024-11-22T11:08:03.166+08:00"},{"id":34613780,"file_name":"12.png","project_id":890319,"asset_id":793545,"created_at":"2024-11-22T11:08:03.167+08:00","updated_at":"2024-11-22T11:08:03.167+08:00"},{"id":34613781,"file_name":"2.png","project_id":890319,"asset_id":793546,"created_at":"2024-11-22T11:08:03.168+08:00","updated_at":"2024-11-22T11:08:03.168+08:00"},{"id":34613782,"file_name":"3.png","project_id":890319,"asset_id":793547,"created_at":"2024-11-22T11:08:03.169+08:00","updated_at":"2024-11-22T11:08:03.169+08:00"},{"id":34613783,"file_name":"end_6.png","project_id":890319,"asset_id":793548,"created_at":"2024-11-22T11:08:03.170+08:00","updated_at":"2024-11-22T11:08:03.170+08:00"},{"id":34613784,"file_name":"end_7.png","project_id":890319,"asset_id":793549,"created_at":"2024-11-22T11:08:03.171+08:00","updated_at":"2024-11-22T11:08:03.171+08:00"},{"id":34613785,"file_name":"0.png","project_id":890319,"asset_id":793550,"created_at":"2024-11-22T11:08:03.172+08:00","updated_at":"2024-11-22T11:08:03.172+08:00"},{"id":34613786,"file_name":"1.png","project_id":890319,"asset_id":793551,"created_at":"2024-11-22T11:08:03.173+08:00","updated_at":"2024-11-22T11:08:03.173+08:00"},{"id":34613787,"file_name":"10.png","project_id":890319,"asset_id":793552,"created_at":"2024-11-22T11:08:03.175+08:00","updated_at":"2024-11-22T11:08:03.175+08:00"},{"id":34613788,"file_name":"11.png","project_id":890319,"asset_id":793553,"created_at":"2024-11-22T11:08:03.176+08:00","updated_at":"2024-11-22T11:08:03.176+08:00"},{"id":34613789,"file_name":"bg.png","project_id":890319,"asset_id":793554,"created_at":"2024-11-22T11:08:03.177+08:00","updated_at":"2024-11-22T11:08:03.177+08:00"},{"id":34613790,"file_name":"end_2.png","project_id":890319,"asset_id":793555,"created_at":"2024-11-22T11:08:03.178+08:00","updated_at":"2024-11-22T11:08:03.178+08:00"},{"id":34613791,"file_name":"end_3.png","project_id":890319,"asset_id":793556,"created_at":"2024-11-22T11:08:03.179+08:00","updated_at":"2024-11-22T11:08:03.179+08:00"},{"id":34613792,"file_name":"end_4.png","project_id":890319,"asset_id":793557,"created_at":"2024-11-22T11:08:03.180+08:00","updated_at":"2024-11-22T11:08:03.180+08:00"},{"id":34613793,"file_name":"end_5.png","project_id":890319,"asset_id":793558,"created_at":"2024-11-22T11:08:03.180+08:00","updated_at":"2024-11-22T11:08:03.180+08:00"},{"id":34613794,"file_name":"4.png","project_id":890319,"asset_id":793559,"created_at":"2024-11-22T11:08:03.182+08:00","updated_at":"2024-11-22T11:08:03.182+08:00"},{"id":34613795,"file_name":"5.png","project_id":890319,"asset_id":793560,"created_at":"2024-11-22T11:08:03.183+08:00","updated_at":"2024-11-22T11:08:03.183+08:00"},{"id":34613796,"file_name":"6.png","project_id":890319,"asset_id":793561,"created_at":"2024-11-22T11:08:03.184+08:00","updated_at":"2024-11-22T11:08:03.184+08:00"},{"id":34613797,"file_name":"7.png","project_id":890319,"asset_id":793562,"created_at":"2024-11-22T11:08:03.185+08:00","updated_at":"2024-11-22T11:08:03.185+08:00"},{"id":34613798,"file_name":"bgm.mp3","project_id":890319,"asset_id":793563,"created_at":"2024-11-22T11:08:03.186+08:00","updated_at":"2024-11-22T11:08:03.186+08:00"},{"id":34613799,"file_name":"rise.mp3","project_id":890319,"asset_id":793564,"created_at":"2024-11-22T11:08:03.187+08:00","updated_at":"2024-11-22T11:08:03.187+08:00"},{"id":34613800,"file_name":"end_10.png","project_id":890319,"asset_id":793565,"created_at":"2024-11-22T11:08:03.188+08:00","updated_at":"2024-11-22T11:08:03.188+08:00"},{"id":34613801,"file_name":"end_11.png","project_id":890319,"asset_id":793566,"created_at":"2024-11-22T11:08:03.189+08:00","updated_at":"2024-11-22T11:08:03.189+08:00"},{"id":34613802,"file_name":"end_8.png","project_id":890319,"asset_id":793567,"created_at":"2024-11-22T11:08:03.190+08:00","updated_at":"2024-11-22T11:08:03.190+08:00"},{"id":34613803,"file_name":"end_9.png","project_id":890319,"asset_id":793568,"created_at":"2024-11-22T11:08:03.191+08:00","updated_at":"2024-11-22T11:08:03.191+08:00"},{"id":34613804,"file_name":"hit.mp3","project_id":890319,"asset_id":793569,"created_at":"2024-11-22T11:08:03.192+08:00","updated_at":"2024-11-22T11:08:03.192+08:00"},{"id":34613805,"file_name":"8.png","project_id":890319,"asset_id":793570,"created_at":"2024-11-22T11:08:03.193+08:00","updated_at":"2024-11-22T11:08:03.193+08:00"},{"id":34613806,"file_name":"9.png","project_id":890319,"asset_id":793571,"created_at":"2024-11-22T11:08:03.194+08:00","updated_at":"2024-11-22T11:08:03.194+08:00"},{"id":34613807,"file_name":"gameover.mp3","project_id":890319,"asset_id":793572,"created_at":"2024-11-22T11:08:03.195+08:00","updated_at":"2024-11-22T11:08:03.195+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦