{"id":725744,"student_id":10,"content":"from game import *\nfrom random import *\n\nX = None #點擊的 X 位置\nY = None #點擊的 Y 位置\nscore = 0 #玩家分數\ncombo = 0 #連續得分\ncount = 0\ngrid = [[],[],[],[],[],[],[],[]] #儲存所有動物角色\nimgs = [str(i) + '.png' for i in range(16)] #動物造型圖片\n\n#創造 64 個動物\nfor x in range(8):\n for y in range(8):\n b = create_sprite(imgs)\n grid[x].append(b)\n\nset_backdrop('bg.png') #設定背景\ntarget = create_sprite('target.png') #創造準星\nline = create_sprite('line.png') #創造血量條\ncreate_sprite('cover.png') #創造背板圖片\ninfo = create_sprite('rules.png', 'end.png') #遊戲說明與結束\nbgm = create_sound('bgm.wav', True) #背景音樂\nalarm = create_sound('alert.wav', True) #背景音樂\nalarm.set_volume(0)\n\n#開始遊戲\ndef start_game():\n global X, Y, score\n if info.y \u003c 450: return\n line.move_to(1075, 400 + 700)\n target.hidden = True\n info.hidden = True\n X = None\n Y = None\n score = 0\n for row in grid:\n for cell in row:\n cell.costume_id = randrange(7)\n\n \n#遊戲主迴圈\ndef loop():\n if info.hidden:\n draw_text(score, 1024, 787, '#b67760', 40)\n update_grid() #更新動物們\n update_life() #更新血量條\n check_grid() #檢查連線並消除\n \n elif info.costume_id == 1 and info.y \u003e= 450:\n draw_text(f'獲得 {score} 分', 400, 400, '#3a483f', 80)\n if info.y \u003c 450: info.y += 5\n\n#更新怒氣\ndef update_life():\n line.y -= 0.3 + count * 0.003\n if line.y \u003e 1100: line.y = 1100\n if line.y \u003c= 400: gameover()\n alarm.set_volume(0.5 if line.y \u003c= 600 and info.hidden else 0)\n\n#更新動物們\ndef update_grid():\n for x in range(8):\n for y in range(8):\n b = grid[x][y]\n tx = x * 100 + 140\n ty = y * 100 + 100\n if b.x \u003e tx: b.x -= 10\n if b.x \u003c tx: b.x += 10\n if b.y \u003e ty: b.y -= 10\n if b.y \u003c ty: b.y += 10\n fade_rm(x, y)\n\n# 淡出並消除\ndef fade_rm(x, y):\n global score\n b = grid[x][y]\n if b.costume_id \u003e= 8: b.opacity -= 0.01\n if b.opacity \u003c= 0.6:\n b.opacity = 1\n b.costume_id = randrange(8)\n b.y = grid[x][0].y - 100\n grid[x].pop(y)\n grid[x].insert(0, b)\n score += combo * 10\n line.y += 30\n\n#檢查十六個行列連線\ndef check_grid():\n for i in range(8):\n v = [row[i] for row in grid]\n h = grid[i]\n check_line(v)\n check_line(h)\n\n#檢查某一行連線\ndef check_line(arr):\n global combo, count\n for i in range(6):\n a = arr[i + 0]\n b = arr[i + 1]\n c = arr[i + 2]\n if a.costume_id % 8 == b.costume_id % 8 == c.costume_id % 8:\n if a.costume_id \u003c 8:\n a.costume_id += 8\n combo += 1\n count += 1\n create_sound(str(combo % 4) + '.wav')\n if b.costume_id \u003c 8: b.costume_id += 8\n if c.costume_id \u003c 8: c.costume_id += 8\n\n#遊戲結束\ndef gameover():\n info.costume_id = 1\n info.hidden = False\n info.y = -450\n \n#畫面點擊\ndef click():\n global X, Y, combo, count\n x = (cursor.x - 90) // 100\n y = (cursor.y - 50) // 100\n if x \u003c 0 or y \u003c 0 or x \u003e 7 or y \u003e 7 or not info.hidden: return\n if X == None or abs(X - x) + abs(Y - y) \u003e 1:\n X = x\n Y = y\n target.move_to(grid[x][y])\n target.hidden = False\n create_sound('click.wav')\n else:\n swap(x, y, X, Y)\n X = None\n Y = None\n line.y -= 50\n combo = 0\n target.hidden = True\n\n#交換兩個角色位置\ndef swap(x1, y1, x2, y2):\n tmp = grid[x1][y1]\n grid[x1][y1] = grid[x2][y2]\n grid[x2][y2] = tmp\n\n\nforever(loop) #不斷執行遊戲迴圈\non('click', click) #當畫面被點擊時\ninfo.on('click', start_game) #點擊說明圖開始遊戲\n\n\n","created_at":"2024-04-03T11:30:14.407+08:00","updated_at":"2024-08-29T18:42:17.224+08:00","name":"動物管理員_預設版","language":"python","screenshot":{"url":"https://cdn2.koding.school/uploads/project/screenshot/725744/1a827be2c6da0c860bfc68772741ec32.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":151,"hashid":"ej9semwv5","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":16225515,"file_name":"0.wav","project_id":725744,"asset_id":732363,"created_at":"2024-04-03T12:07:02.387+08:00","updated_at":"2024-04-03T18:42:47.977+08:00"},{"id":16225516,"file_name":"1.wav","project_id":725744,"asset_id":732365,"created_at":"2024-04-03T12:07:02.389+08:00","updated_at":"2024-04-03T18:42:50.512+08:00"},{"id":16225518,"file_name":"3.wav","project_id":725744,"asset_id":732367,"created_at":"2024-04-03T12:07:03.322+08:00","updated_at":"2024-04-03T18:42:55.907+08:00"},{"id":16225517,"file_name":"2.wav","project_id":725744,"asset_id":732366,"created_at":"2024-04-03T12:07:03.320+08:00","updated_at":"2024-04-03T18:42:54.244+08:00"},{"id":16241214,"file_name":"line.png","project_id":725744,"asset_id":732642,"created_at":"2024-04-10T11:07:34.889+08:00","updated_at":"2024-04-10T11:07:34.889+08:00"},{"id":16238715,"file_name":"end.png","project_id":725744,"asset_id":732223,"created_at":"2024-04-09T12:43:21.466+08:00","updated_at":"2024-04-09T12:43:21.466+08:00"},{"id":16241466,"file_name":"bgm.mp3","project_id":725744,"asset_id":732643,"created_at":"2024-04-10T14:26:55.873+08:00","updated_at":"2024-04-10T14:26:55.873+08:00"},{"id":16241211,"file_name":"bg.png","project_id":725744,"asset_id":732639,"created_at":"2024-04-10T11:01:49.144+08:00","updated_at":"2024-04-10T11:01:49.144+08:00"},{"id":16241212,"file_name":"cover.png","project_id":725744,"asset_id":732640,"created_at":"2024-04-10T11:01:49.148+08:00","updated_at":"2024-04-10T11:01:49.148+08:00"},{"id":16238713,"file_name":"rules.png","project_id":725744,"asset_id":732340,"created_at":"2024-04-09T12:41:23.252+08:00","updated_at":"2024-04-09T12:41:23.252+08:00"},{"id":16238714,"file_name":"target.png","project_id":725744,"asset_id":732593,"created_at":"2024-04-09T12:41:23.254+08:00","updated_at":"2024-04-09T12:41:23.254+08:00"},{"id":16241365,"file_name":"2.png","project_id":725744,"asset_id":732325,"created_at":"2024-04-10T12:25:24.921+08:00","updated_at":"2024-04-10T12:25:24.921+08:00"},{"id":16241366,"file_name":"3.png","project_id":725744,"asset_id":732327,"created_at":"2024-04-10T12:25:24.924+08:00","updated_at":"2024-04-10T12:25:24.924+08:00"},{"id":16241430,"file_name":"click.wav","project_id":725744,"asset_id":172283,"created_at":"2024-04-10T14:15:11.590+08:00","updated_at":"2024-04-10T14:15:11.590+08:00"},{"id":16241363,"file_name":"0.png","project_id":725744,"asset_id":732321,"created_at":"2024-04-10T12:25:24.531+08:00","updated_at":"2024-04-10T12:25:24.531+08:00"},{"id":16241364,"file_name":"1.png","project_id":725744,"asset_id":732323,"created_at":"2024-04-10T12:25:24.534+08:00","updated_at":"2024-04-10T12:25:24.534+08:00"},{"id":16241377,"file_name":"14.png","project_id":725744,"asset_id":732589,"created_at":"2024-04-10T12:25:27.459+08:00","updated_at":"2024-04-10T12:25:27.459+08:00"},{"id":16241378,"file_name":"15.png","project_id":725744,"asset_id":732590,"created_at":"2024-04-10T12:25:27.461+08:00","updated_at":"2024-04-10T12:25:27.461+08:00"},{"id":16241367,"file_name":"4.png","project_id":725744,"asset_id":732329,"created_at":"2024-04-10T12:25:25.311+08:00","updated_at":"2024-04-10T12:25:25.311+08:00"},{"id":16241368,"file_name":"5.png","project_id":725744,"asset_id":732331,"created_at":"2024-04-10T12:25:25.314+08:00","updated_at":"2024-04-10T12:25:25.314+08:00"},{"id":16241640,"file_name":"alarm.ogg","project_id":725744,"asset_id":732644,"created_at":"2024-04-10T18:03:18.076+08:00","updated_at":"2024-04-10T18:03:18.076+08:00"},{"id":16241371,"file_name":"8.png","project_id":725744,"asset_id":732583,"created_at":"2024-04-10T12:25:26.094+08:00","updated_at":"2024-04-10T12:25:26.094+08:00"},{"id":16241372,"file_name":"9.png","project_id":725744,"asset_id":732584,"created_at":"2024-04-10T12:25:26.096+08:00","updated_at":"2024-04-10T12:25:26.096+08:00"},{"id":16241373,"file_name":"10.png","project_id":725744,"asset_id":732585,"created_at":"2024-04-10T12:25:26.463+08:00","updated_at":"2024-04-10T12:25:26.463+08:00"},{"id":16241374,"file_name":"11.png","project_id":725744,"asset_id":732586,"created_at":"2024-04-10T12:25:26.465+08:00","updated_at":"2024-04-10T12:25:26.465+08:00"},{"id":16241375,"file_name":"12.png","project_id":725744,"asset_id":732587,"created_at":"2024-04-10T12:25:26.857+08:00","updated_at":"2024-04-10T12:25:26.857+08:00"},{"id":16241376,"file_name":"13.png","project_id":725744,"asset_id":732588,"created_at":"2024-04-10T12:25:26.859+08:00","updated_at":"2024-04-10T12:25:26.859+08:00"},{"id":16241641,"file_name":"bgm.wav","project_id":725744,"asset_id":732645,"created_at":"2024-04-10T18:12:45.361+08:00","updated_at":"2024-04-10T18:12:45.361+08:00"},{"id":16241369,"file_name":"6.png","project_id":725744,"asset_id":732333,"created_at":"2024-04-10T12:25:25.715+08:00","updated_at":"2024-04-10T12:25:25.715+08:00"},{"id":16241370,"file_name":"7.png","project_id":725744,"asset_id":732335,"created_at":"2024-04-10T12:25:25.717+08:00","updated_at":"2024-04-10T12:25:25.717+08:00"},{"id":16241642,"file_name":"alert.wav","project_id":725744,"asset_id":732646,"created_at":"2024-04-10T18:12:57.986+08:00","updated_at":"2024-04-10T18:12:57.986+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦