{"id":755496,"student_id":10,"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 pass\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 != 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 for b in arr: b.x += 20\n bg.x += 20\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 for b in arr: b.x -= 20\n bg.x -= 20\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 for b in arr: b.y += 20\n bg.y += 20\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 for b in arr: b.y -= 20\n bg.y -= 20\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)\narr[0].costume_id = 1\narr[2].costume_id = 1\n\n","created_at":"2024-05-22T11:07:30.097+08:00","updated_at":"2024-10-25T11:44:28.191+08:00","name":"熱量大作戰(預設版)","language":"python","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/755496/c306b4e5ccc43481e53c8eb2145f047e.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":138,"hashid":"6rpsqp6q8","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":16869431,"file_name":"end_1.png","project_id":755496,"asset_id":743189,"created_at":"2024-05-22T11:07:46.867+08:00","updated_at":"2024-05-22T11:07:46.867+08:00"},{"id":16869442,"file_name":"end_12.png","project_id":755496,"asset_id":743200,"created_at":"2024-05-22T11:07:53.029+08:00","updated_at":"2024-05-22T11:07:53.029+08:00"},{"id":16869443,"file_name":"rules.png","project_id":755496,"asset_id":743201,"created_at":"2024-05-22T11:07:53.030+08:00","updated_at":"2024-05-22T11:07:53.030+08:00"},{"id":16869428,"file_name":"12.png","project_id":755496,"asset_id":743186,"created_at":"2024-05-22T11:07:46.180+08:00","updated_at":"2024-05-22T11:07:46.180+08:00"},{"id":16869418,"file_name":"2.png","project_id":755496,"asset_id":743176,"created_at":"2024-05-22T11:07:42.612+08:00","updated_at":"2024-05-22T11:07:42.612+08:00"},{"id":16869419,"file_name":"3.png","project_id":755496,"asset_id":743177,"created_at":"2024-05-22T11:07:42.614+08:00","updated_at":"2024-05-22T11:07:42.614+08:00"},{"id":16869436,"file_name":"end_6.png","project_id":755496,"asset_id":743194,"created_at":"2024-05-22T11:07:49.708+08:00","updated_at":"2024-05-22T11:07:49.708+08:00"},{"id":16869437,"file_name":"end_7.png","project_id":755496,"asset_id":743195,"created_at":"2024-05-22T11:07:49.710+08:00","updated_at":"2024-05-22T11:07:49.710+08:00"},{"id":16869416,"file_name":"0.png","project_id":755496,"asset_id":743174,"created_at":"2024-05-22T11:07:42.154+08:00","updated_at":"2024-05-22T11:07:42.154+08:00"},{"id":16869417,"file_name":"1.png","project_id":755496,"asset_id":743175,"created_at":"2024-05-22T11:07:42.156+08:00","updated_at":"2024-05-22T11:07:42.156+08:00"},{"id":16869426,"file_name":"10.png","project_id":755496,"asset_id":743184,"created_at":"2024-05-22T11:07:45.040+08:00","updated_at":"2024-05-22T11:07:45.040+08:00"},{"id":16869427,"file_name":"11.png","project_id":755496,"asset_id":743185,"created_at":"2024-05-22T11:07:45.042+08:00","updated_at":"2024-05-22T11:07:45.042+08:00"},{"id":16869448,"file_name":"bg.png","project_id":755496,"asset_id":743202,"created_at":"2024-05-22T11:23:33.013+08:00","updated_at":"2024-05-22T11:23:33.013+08:00"},{"id":16869432,"file_name":"end_2.png","project_id":755496,"asset_id":743190,"created_at":"2024-05-22T11:07:47.792+08:00","updated_at":"2024-05-22T11:07:47.792+08:00"},{"id":16869433,"file_name":"end_3.png","project_id":755496,"asset_id":743191,"created_at":"2024-05-22T11:07:47.793+08:00","updated_at":"2024-05-22T11:07:47.793+08:00"},{"id":16869434,"file_name":"end_4.png","project_id":755496,"asset_id":743192,"created_at":"2024-05-22T11:07:48.742+08:00","updated_at":"2024-05-22T11:07:48.742+08:00"},{"id":16869435,"file_name":"end_5.png","project_id":755496,"asset_id":743193,"created_at":"2024-05-22T11:07:48.744+08:00","updated_at":"2024-05-22T11:07:48.744+08:00"},{"id":16869420,"file_name":"4.png","project_id":755496,"asset_id":743178,"created_at":"2024-05-22T11:07:43.048+08:00","updated_at":"2024-05-22T11:07:43.048+08:00"},{"id":16869421,"file_name":"5.png","project_id":755496,"asset_id":743179,"created_at":"2024-05-22T11:07:43.050+08:00","updated_at":"2024-05-22T11:07:43.050+08:00"},{"id":16869422,"file_name":"6.png","project_id":755496,"asset_id":743180,"created_at":"2024-05-22T11:07:43.490+08:00","updated_at":"2024-05-22T11:07:43.490+08:00"},{"id":16869423,"file_name":"7.png","project_id":755496,"asset_id":743181,"created_at":"2024-05-22T11:07:43.491+08:00","updated_at":"2024-05-22T11:07:43.491+08:00"},{"id":16869444,"file_name":"bgm.mp3","project_id":755496,"asset_id":735954,"created_at":"2024-05-22T11:08:40.433+08:00","updated_at":"2024-05-22T11:08:40.433+08:00"},{"id":16869446,"file_name":"rise.mp3","project_id":755496,"asset_id":735953,"created_at":"2024-05-22T11:09:21.587+08:00","updated_at":"2024-05-22T11:09:21.587+08:00"},{"id":16869440,"file_name":"end_10.png","project_id":755496,"asset_id":743198,"created_at":"2024-05-22T11:07:51.972+08:00","updated_at":"2024-05-22T11:07:51.972+08:00"},{"id":16869441,"file_name":"end_11.png","project_id":755496,"asset_id":743199,"created_at":"2024-05-22T11:07:51.973+08:00","updated_at":"2024-05-22T11:07:51.973+08:00"},{"id":16869438,"file_name":"end_8.png","project_id":755496,"asset_id":743196,"created_at":"2024-05-22T11:07:50.580+08:00","updated_at":"2024-05-22T11:07:50.580+08:00"},{"id":16869439,"file_name":"end_9.png","project_id":755496,"asset_id":743197,"created_at":"2024-05-22T11:07:50.582+08:00","updated_at":"2024-05-22T11:07:50.582+08:00"},{"id":16869445,"file_name":"hit.mp3","project_id":755496,"asset_id":735950,"created_at":"2024-05-22T11:09:10.365+08:00","updated_at":"2024-05-22T11:09:10.365+08:00"},{"id":16869424,"file_name":"8.png","project_id":755496,"asset_id":743182,"created_at":"2024-05-22T11:07:43.943+08:00","updated_at":"2024-05-22T11:07:43.943+08:00"},{"id":16869425,"file_name":"9.png","project_id":755496,"asset_id":743183,"created_at":"2024-05-22T11:07:43.944+08:00","updated_at":"2024-05-22T11:07:43.944+08:00"},{"id":16869447,"file_name":"gameover.mp3","project_id":755496,"asset_id":735951,"created_at":"2024-05-22T11:09:34.015+08:00","updated_at":"2024-05-22T11:09:34.015+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦