{"id":863583,"student_id":1981,"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 \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 pass\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 pass\n\nforever(loop) #不斷執行遊戲迴圈\non('click', click) #當畫面被點擊時\ninfo.on('click', start_game) #點擊說明圖開始遊戲\n\n\n","created_at":"2024-10-15T16:11:56.204+08:00","updated_at":"2024-10-15T16:11:56.204+08:00","name":"5_動物管理員_預設版 副本","language":"python","screenshot":{"url":null},"parent_id":830565,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":3,"hashid":"d5ms93qqw","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":18911820,"file_name":"0.wav","project_id":863583,"asset_id":772497,"created_at":"2024-10-15T16:11:56.209+08:00","updated_at":"2024-10-15T16:11:56.209+08:00"},{"id":18911821,"file_name":"1.wav","project_id":863583,"asset_id":772498,"created_at":"2024-10-15T16:11:56.210+08:00","updated_at":"2024-10-15T16:11:56.210+08:00"},{"id":18911822,"file_name":"3.wav","project_id":863583,"asset_id":772499,"created_at":"2024-10-15T16:11:56.211+08:00","updated_at":"2024-10-15T16:11:56.211+08:00"},{"id":18911823,"file_name":"2.wav","project_id":863583,"asset_id":772500,"created_at":"2024-10-15T16:11:56.212+08:00","updated_at":"2024-10-15T16:11:56.212+08:00"},{"id":18911824,"file_name":"line.png","project_id":863583,"asset_id":772501,"created_at":"2024-10-15T16:11:56.213+08:00","updated_at":"2024-10-15T16:11:56.213+08:00"},{"id":18911825,"file_name":"end.png","project_id":863583,"asset_id":772502,"created_at":"2024-10-15T16:11:56.214+08:00","updated_at":"2024-10-15T16:11:56.214+08:00"},{"id":18911826,"file_name":"bgm.mp3","project_id":863583,"asset_id":772503,"created_at":"2024-10-15T16:11:56.215+08:00","updated_at":"2024-10-15T16:11:56.215+08:00"},{"id":18911827,"file_name":"bg.png","project_id":863583,"asset_id":772504,"created_at":"2024-10-15T16:11:56.215+08:00","updated_at":"2024-10-15T16:11:56.215+08:00"},{"id":18911828,"file_name":"cover.png","project_id":863583,"asset_id":772505,"created_at":"2024-10-15T16:11:56.216+08:00","updated_at":"2024-10-15T16:11:56.216+08:00"},{"id":18911829,"file_name":"rules.png","project_id":863583,"asset_id":772506,"created_at":"2024-10-15T16:11:56.217+08:00","updated_at":"2024-10-15T16:11:56.217+08:00"},{"id":18911830,"file_name":"target.png","project_id":863583,"asset_id":772507,"created_at":"2024-10-15T16:11:56.218+08:00","updated_at":"2024-10-15T16:11:56.218+08:00"},{"id":18911831,"file_name":"2.png","project_id":863583,"asset_id":772508,"created_at":"2024-10-15T16:11:56.219+08:00","updated_at":"2024-10-15T16:11:56.219+08:00"},{"id":18911832,"file_name":"3.png","project_id":863583,"asset_id":772509,"created_at":"2024-10-15T16:11:56.220+08:00","updated_at":"2024-10-15T16:11:56.220+08:00"},{"id":18911833,"file_name":"click.wav","project_id":863583,"asset_id":772510,"created_at":"2024-10-15T16:11:56.221+08:00","updated_at":"2024-10-15T16:11:56.221+08:00"},{"id":18911834,"file_name":"0.png","project_id":863583,"asset_id":772511,"created_at":"2024-10-15T16:11:56.222+08:00","updated_at":"2024-10-15T16:11:56.222+08:00"},{"id":18911835,"file_name":"1.png","project_id":863583,"asset_id":772512,"created_at":"2024-10-15T16:11:56.222+08:00","updated_at":"2024-10-15T16:11:56.222+08:00"},{"id":18911836,"file_name":"14.png","project_id":863583,"asset_id":772513,"created_at":"2024-10-15T16:11:56.223+08:00","updated_at":"2024-10-15T16:11:56.223+08:00"},{"id":18911837,"file_name":"15.png","project_id":863583,"asset_id":772514,"created_at":"2024-10-15T16:11:56.224+08:00","updated_at":"2024-10-15T16:11:56.224+08:00"},{"id":18911838,"file_name":"4.png","project_id":863583,"asset_id":772515,"created_at":"2024-10-15T16:11:56.225+08:00","updated_at":"2024-10-15T16:11:56.225+08:00"},{"id":18911839,"file_name":"5.png","project_id":863583,"asset_id":772516,"created_at":"2024-10-15T16:11:56.226+08:00","updated_at":"2024-10-15T16:11:56.226+08:00"},{"id":18911840,"file_name":"alarm.ogg","project_id":863583,"asset_id":772517,"created_at":"2024-10-15T16:11:56.227+08:00","updated_at":"2024-10-15T16:11:56.227+08:00"},{"id":18911841,"file_name":"8.png","project_id":863583,"asset_id":772518,"created_at":"2024-10-15T16:11:56.228+08:00","updated_at":"2024-10-15T16:11:56.228+08:00"},{"id":18911842,"file_name":"9.png","project_id":863583,"asset_id":772519,"created_at":"2024-10-15T16:11:56.229+08:00","updated_at":"2024-10-15T16:11:56.229+08:00"},{"id":18911843,"file_name":"10.png","project_id":863583,"asset_id":772520,"created_at":"2024-10-15T16:11:56.230+08:00","updated_at":"2024-10-15T16:11:56.230+08:00"},{"id":18911844,"file_name":"11.png","project_id":863583,"asset_id":772521,"created_at":"2024-10-15T16:11:56.231+08:00","updated_at":"2024-10-15T16:11:56.231+08:00"},{"id":18911845,"file_name":"12.png","project_id":863583,"asset_id":772522,"created_at":"2024-10-15T16:11:56.231+08:00","updated_at":"2024-10-15T16:11:56.231+08:00"},{"id":18911846,"file_name":"13.png","project_id":863583,"asset_id":772523,"created_at":"2024-10-15T16:11:56.232+08:00","updated_at":"2024-10-15T16:11:56.232+08:00"},{"id":18911847,"file_name":"bgm.wav","project_id":863583,"asset_id":772524,"created_at":"2024-10-15T16:11:56.233+08:00","updated_at":"2024-10-15T16:11:56.233+08:00"},{"id":18911848,"file_name":"6.png","project_id":863583,"asset_id":772525,"created_at":"2024-10-15T16:11:56.234+08:00","updated_at":"2024-10-15T16:11:56.234+08:00"},{"id":18911849,"file_name":"7.png","project_id":863583,"asset_id":772526,"created_at":"2024-10-15T16:11:56.235+08:00","updated_at":"2024-10-15T16:11:56.235+08:00"},{"id":18911850,"file_name":"alert.wav","project_id":863583,"asset_id":772527,"created_at":"2024-10-15T16:11:56.236+08:00","updated_at":"2024-10-15T16:11:56.236+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦