{"id":202940,"student_id":10,"content":"from game import *\nfrom random import *\n\ngame.set_backdrop('bg_3.png')\n\nfood = create_sprite('food.png')\n\np1_head = create_sprite('red.png')\np1_body = [create_sprite('red.png')]\np1_gameover = False\n\np1_head.x = 100\n\np2_head = create_sprite('blue.png')\np2_body = [create_sprite('blue.png')]\np2_gameover = False\n\np2_head.x = 1100\n\np3_head = create_sprite('green.png')\np3_body = [create_sprite('green.png')]\np3_gameover = False\n\np3_head.x = 300\n\nclock = 0\n\ndef loop():\n global clock\n clock += 1\n p1_loop()\n p2_loop()\n p3_loop()\n \ndef p1_loop():\n global p1_body, p1_gameover\n \n if key.left: p1_head.direction -= 3\n if key.right: p1_head.direction += 3\n \n if p1_head.x \u003e 1200: p1_head.x -= 1200\n if p1_head.x \u003c 0: p1_head.x += 1200\n if p1_head.y \u003e 900: p1_head.y -= 900\n if p1_head.y \u003c 0: p1_head.y += 900\n \n if clock % 5 == 0 and p1_gameover == False:\n b = p1_body.pop()\n b.layer = clock\n b.move_to(p1_head)\n b.direction = p1_head.direction\n p1_body = [b] + p1_body\n \n if key.up:\n p1_head.step_forward(30)\n else:\n p1_head.step_forward(15)\n\n \n if p1_head.touched(food):\n food.x = randrange(100, 1100)\n food.y = randrange(100, 800)\n b = create_sprite('red.png')\n b.move_to(p1_head)\n p1_body.append(b)\n \n if p1_head.touched(p2_body) or p1_head.touched(p3_body):\n p1_gameover = True\n \n\ndef p2_loop():\n global p2_body, p2_gameover\n \n if key.a: p2_head.direction -= 3\n if key.d: p2_head.direction += 3\n \n if p2_head.x \u003e 1200: p2_head.x -= 1200\n if p2_head.x \u003c 0: p2_head.x += 1200\n if p2_head.y \u003e 900: p2_head.y -= 900\n if p2_head.y \u003c 0: p2_head.y += 900\n \n if clock % 5 == 0 and p2_gameover == False:\n b = p2_body.pop()\n b.layer = clock\n b.move_to(p2_head)\n b.direction = p2_head.direction\n p2_body = [b] + p2_body\n if key.w:\n p2_head.step_forward(30)\n else:\n p2_head.step_forward(15)\n \n if p2_head.touched(food):\n food.x = randrange(100, 1100)\n food.y = randrange(100, 800)\n b = create_sprite('blue.png')\n b.move_to(p2_head)\n p2_body.append(b)\n \n if p2_head.touched(p1_body) or p2_head.touched(p3_body):\n p2_gameover = True\n\n\ndef p3_loop():\n global p3_body, p3_gameover\n \n if key.j: p3_head.direction -= 3\n if key.l: p3_head.direction += 3\n \n if p3_head.x \u003e 1200: p3_head.x -= 1200\n if p3_head.x \u003c 0: p3_head.x += 1200\n if p3_head.y \u003e 900: p3_head.y -= 900\n if p3_head.y \u003c 0: p3_head.y += 900\n \n if clock % 5 == 0 and p3_gameover == False:\n b = p3_body.pop()\n b.layer = clock\n b.move_to(p3_head)\n b.direction = p3_head.direction\n p3_body = [b] + p3_body\n \n if key.w:\n p3_head.step_forward(30)\n else:\n p3_head.step_forward(15)\n\n if p3_head.touched(food):\n food.x = randrange(100, 1100)\n food.y = randrange(100, 800)\n b = create_sprite('green.png')\n b.move_to(p3_head)\n p3_body.append(b)\n \n if p3_head.touched(p1_body) or p3_head.touched(p2_body):\n p3_gameover = True\n\nforever(loop)\n\n","created_at":"2020-11-10T15:36:49.992+08:00","updated_at":"2020-11-26T23:40:16.120+08:00","name":"雙人貪食蛇","language":"python","screenshot":{"url":"https://cdn6.koding.school/uploads/project/screenshot/202940/f956ba5cad94bb0809ea41e7964932c8.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":215,"hashid":"9ygspqw5m","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3504558,"file_name":"food.png","project_id":202940,"asset_id":280310,"created_at":"2020-11-10T15:37:52.172+08:00","updated_at":"2020-11-10T15:37:52.172+08:00"},{"id":3504555,"file_name":"blue.png","project_id":202940,"asset_id":280307,"created_at":"2020-11-10T15:37:11.452+08:00","updated_at":"2020-11-10T15:37:11.452+08:00"},{"id":3504556,"file_name":"green.png","project_id":202940,"asset_id":280308,"created_at":"2020-11-10T15:37:11.454+08:00","updated_at":"2020-11-10T15:37:11.454+08:00"},{"id":3504557,"file_name":"red.png","project_id":202940,"asset_id":280309,"created_at":"2020-11-10T15:37:12.135+08:00","updated_at":"2020-11-10T15:37:12.135+08:00"},{"id":3505012,"file_name":"bg_1.png","project_id":202940,"asset_id":280632,"created_at":"2020-11-10T16:06:26.517+08:00","updated_at":"2020-11-10T16:06:26.517+08:00"},{"id":3505013,"file_name":"bg_2.png","project_id":202940,"asset_id":280633,"created_at":"2020-11-10T16:06:26.519+08:00","updated_at":"2020-11-10T16:06:26.519+08:00"},{"id":3505014,"file_name":"bg_3.png","project_id":202940,"asset_id":280634,"created_at":"2020-11-10T16:06:28.211+08:00","updated_at":"2020-11-10T16:06:28.211+08:00"},{"id":3505015,"file_name":"bg_4.png","project_id":202940,"asset_id":280635,"created_at":"2020-11-10T16:06:28.212+08:00","updated_at":"2020-11-10T16:06:28.212+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦