{"id":711480,"student_id":10,"content":"from game import *\nfrom random import randint\n\narr = []\ntotal = 0\n\nbg = create_sprite(\"bg.png\")\nbg.xx = 600\nbg.yy = 450\n\nfor y in range(4):\n for x in range(4):\n b = create_sprite('0.png', '2.png', '4.png', '8.png', '16.png', '32.png', '128.png', '256.png', '512.png', '1024.png', '2048.png', '4096.png')\n b.x = b.xx = 200 * x + 300\n b.y = b.yy = 200 * y + 150\n b.scale = 0.1\n arr.append(b)\n\ninfo = create_sprite(\"rules.png\", \"end.png\")\n\ndef loop():\n for b in arr + [bg]:\n if b.x \u003e b.xx: b.x -= 10\n if b.x \u003c b.xx: b.x += 10\n if b.y \u003e b.yy: b.y -= 10\n if b.y \u003c b.yy: b.y += 10\n if b.scale \u003e= 1.04: b.scale -= 0.04\n elif b.scale \u003c= 0.96: b.scale += 0.04\n \n if info.costume_id != 0 and not info.hidden:\n draw_text('累積 ' + str(total) + ' 大卡', 450, 700, 'red', 60)\n\ndef start_game():\n for b in arr: b.costume_id = 0\n for i in range(2): add()\n info.hidden = True\n\ndef add():\n global total\n empty = []\n for b in arr:\n if b.costume_id == 0:\n empty.append(b)\n if len(empty) == 0:\n gameover()\n else:\n rand = randint(0, len(empty) - 1)\n empty[rand].costume_id = randint(1, 2)\n empty[rand].scale = 0.1\n total += empty[rand].costume_id\n \ndef move(a, b, c, d):\n if d.costume_id == 0:\n d.costume_id = c.costume_id\n c.costume_id = 0\n if c.costume_id == 0:\n c.costume_id = b.costume_id\n b.costume_id = 0\n if b.costume_id == 0:\n b.costume_id = a.costume_id\n a.costume_id = 0\n if d.costume_id == 0:\n d.costume_id = c.costume_id\n c.costume_id = 0\n if c.costume_id == 0:\n c.costume_id = b.costume_id\n b.costume_id = 0\n if d.costume_id == 0:\n d.costume_id = c.costume_id\n c.costume_id = 0\n if d.costume_id == c.costume_id and d.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 d.scale = 1.3\n if c.costume_id == b.costume_id and c.costume_id != 0:\n c.costume_id += 1\n b.costume_id = a.costume_id\n a.costume_id = 0\n c.scale = 1.3\n if b.costume_id == a.costume_id and b.costume_id != 0:\n b.costume_id += 1\n a.costume_id = 0\n b.scale = 1.3\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 += 30\n bg.x += 30\n add()\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 -= 30\n bg.x -= 30\n add()\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 -= 30\n bg.y -= 30\n add()\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 += 30\n bg.y += 30\n add()\n\ndef gameover():\n info.costume_id = 1\n info.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)\ninfo.on('click', start_game)\nforever(loop)\n","created_at":"2024-03-11T16:14:30.739+08:00","updated_at":"2024-04-16T13:55:02.588+08:00","name":"營養大作戰","language":"python","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/711480/efa14cb290e596f300530c8b9abd73d5.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":50,"hashid":"36ysy98re","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":15916188,"file_name":"2048.png","project_id":711480,"asset_id":726325,"created_at":"2024-03-12T12:44:21.854+08:00","updated_at":"2024-03-12T12:44:21.854+08:00"},{"id":15916189,"file_name":"0.png","project_id":711480,"asset_id":726326,"created_at":"2024-03-12T12:44:41.099+08:00","updated_at":"2024-03-12T12:44:41.099+08:00"},{"id":15916176,"file_name":"8.png","project_id":711480,"asset_id":726317,"created_at":"2024-03-12T12:44:19.881+08:00","updated_at":"2024-03-12T12:44:19.881+08:00"},{"id":15916177,"file_name":"16.png","project_id":711480,"asset_id":726318,"created_at":"2024-03-12T12:44:19.883+08:00","updated_at":"2024-03-12T12:44:19.883+08:00"},{"id":15916178,"file_name":"32.png","project_id":711480,"asset_id":726319,"created_at":"2024-03-12T12:44:20.434+08:00","updated_at":"2024-03-12T12:44:20.434+08:00"},{"id":15916179,"file_name":"128.png","project_id":711480,"asset_id":726320,"created_at":"2024-03-12T12:44:20.435+08:00","updated_at":"2024-03-12T12:44:20.435+08:00"},{"id":15916186,"file_name":"1024.png","project_id":711480,"asset_id":726323,"created_at":"2024-03-12T12:44:21.449+08:00","updated_at":"2024-03-12T12:44:21.449+08:00"},{"id":15916187,"file_name":"4096.png","project_id":711480,"asset_id":726324,"created_at":"2024-03-12T12:44:21.451+08:00","updated_at":"2024-03-12T12:44:21.451+08:00"},{"id":15916174,"file_name":"2.png","project_id":711480,"asset_id":726315,"created_at":"2024-03-12T12:44:19.345+08:00","updated_at":"2024-03-12T12:44:19.345+08:00"},{"id":15916175,"file_name":"4.png","project_id":711480,"asset_id":726316,"created_at":"2024-03-12T12:44:19.347+08:00","updated_at":"2024-03-12T12:44:19.347+08:00"},{"id":15916184,"file_name":"256.png","project_id":711480,"asset_id":726321,"created_at":"2024-03-12T12:44:20.856+08:00","updated_at":"2024-03-12T12:44:20.856+08:00"},{"id":15916185,"file_name":"512.png","project_id":711480,"asset_id":726322,"created_at":"2024-03-12T12:44:20.858+08:00","updated_at":"2024-03-12T12:44:20.858+08:00"},{"id":16332674,"file_name":"bg.png","project_id":711480,"asset_id":734299,"created_at":"2024-04-16T13:10:16.945+08:00","updated_at":"2024-04-16T13:10:16.945+08:00"},{"id":16332675,"file_name":"end.png","project_id":711480,"asset_id":734300,"created_at":"2024-04-16T13:13:39.441+08:00","updated_at":"2024-04-16T13:13:39.441+08:00"},{"id":16332676,"file_name":"rules.png","project_id":711480,"asset_id":734301,"created_at":"2024-04-16T13:13:39.443+08:00","updated_at":"2024-04-16T13:13:39.443+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦