{"id":194872,"student_id":10,"content":"import game\nimport random\n\ngame.set_backdrop('black')\n\np1_head = game.create_sprite('body_g.png')\np2_head = game.create_sprite('body_y.png')\nfood = game.create_sprite('food.png')\n\np1_head.move_to(90, 90)\np2_head.move_to(1170, 90)\n\nfood.x = random.randrange(20) * 60 + 30\nfood.x = random.randrange(15) * 60 + 30\n\np1_bodies = [game.create_sprite('body_g.png')]\np2_bodies = [game.create_sprite('body_y.png')]\n\nclock = 0\n\ndef loop():\n global clock, p1_bodies, p2_bodies\n clock += 1\n \n if game.key.right: p1_head.direction = 90\n if game.key.left: p1_head.direction = 270\n if game.key.up: p1_head.direction = 0\n if game.key.down: p1_head.direction = 180\n \n if clock % 20 == 0:\n if p1_head.touched(food):\n food.x = random.randrange(20) * 60 + 30\n food.x = random.randrange(15) * 60 + 30\n body = game.create_sprite('body_g.png')\n p1_bodies.append(body)\n \n b = p1_bodies.pop()\n b.move_to(p1_head)\n p1_head.step_forward(60)\n p1_bodies = [b] + p1_bodies\n \n if p1_head.touched(p2_bodies):\n game.stop()\n game.draw_text('gameover p2 win', 600, 450, 'white', 80)\n \n \n if game.key.d: p2_head.direction = 90\n if game.key.a: p2_head.direction = 270\n if game.key.w: p2_head.direction = 0\n if game.key.s: p2_head.direction = 180\n \n if clock % 20 == 0:\n if p2_head.touched(food):\n food.x = random.randrange(20) * 60 + 30\n food.x = random.randrange(15) * 60 + 30\n body = game.create_sprite('body_y.png')\n p2_bodies.append(body)\n \n b = p2_bodies.pop()\n b.move_to(p2_head)\n p2_head.step_forward(60)\n p2_bodies = [b] + p2_bodies\n \n if p1_head.touched(p1_bodies):\n game.stop()\n game.draw_text('gameover p1 win', 600, 450, 'white', 80)\n\n\ngame.forever(loop)\n","created_at":"2020-10-14T15:09:17.131+08:00","updated_at":"2020-10-14T15:57:45.427+08:00","name":"雙人貪食蛇","language":"python","screenshot":{"url":"https://cdn3.koding.school/uploads/project/screenshot/194872/88a8d1f57ab60ef9cd78aea86ef96f70.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":236,"hashid":"rdvs6pp95","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3336980,"file_name":"food.png","project_id":194872,"asset_id":268954,"created_at":"2020-10-14T15:09:33.645+08:00","updated_at":"2020-10-14T15:09:33.645+08:00"},{"id":3336978,"file_name":"body_g.png","project_id":194872,"asset_id":268952,"created_at":"2020-10-14T15:09:33.168+08:00","updated_at":"2020-10-14T15:09:33.168+08:00"},{"id":3336979,"file_name":"body_y.png","project_id":194872,"asset_id":268953,"created_at":"2020-10-14T15:09:33.170+08:00","updated_at":"2020-10-14T15:09:33.170+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦