猫史档案馆


【Python作品分享】你吃我吃小游戏【作品秀】

用户:冰凌羽冰凌羽查看:0 回复:0 评论:0 创建时间:2020-04-11T11:46:17


【作品展示】

center_image

 

【作品介绍】

你吃我吃小游戏。

没有抄袭

封面随便选了一个不要介意

(*^▽^*)祝大家玩的愉快。

 

【作品源代码】

import random
import time

print('''玩家选择电脑吃或者玩家吃,
电脑选择苹果或者喵
喵减血,苹果加血''')

class Player():
    def __init__(self,health,choice):
        self.health=health
        self.choice=choice
        print(f'玩家有{self.health}滴血!')
    def choose(self):
        while True:
            self.choice=input("请输入电脑吃或者玩家吃:")
            if self.choice in ['电脑吃','玩家吃']:
                break
            else:
                print('请重新输入')
    def eat_apple(self):
        self.health += 1
        print(f'玩家加1滴血!')
    def eat_duyao(self):
        self.health -= 1
        print(f'玩家减1滴血!')


class Computer():
    def __init__(self, health, choice):
        self.health = health
        self.choice = choice
        print(f'电脑有{self.health}滴血!')

    def choose(self):
        self.choice=random.choice(['苹果','喵'])

    def eat_apple(self):
        self.health += 1
        print(f'电脑加1滴血!')

    def eat_duyao(self):
        self.health -= 1
        print(f'电脑减1滴血!')


player=Player(2,"电脑吃或者玩家吃")
computer = Computer(2, "苹果或者喵")

while True:
    player.choose()
    computer.choose()
    print(f'玩家选择了{player.choice},电脑选择了{computer.choice}')
    def check(a,b):
        if a.choice =="电脑吃":
            if b.choice == "苹果":
                b.eat_apple()
            if b.choice == "喵":
                b.eat_duyao()
        if a.choice == "玩家吃":
            if b.choice == "苹果":
                a.eat_apple()
            if b.choice == "喵":
                a.eat_duyao()
    check(player,computer)
    print(f'玩家还剩{player.health}滴血,电脑还剩{computer.health}滴血')
    if player.health == 0:
        print('玩家输了')
        exit(0)
    if computer.health == 0:
        print('电脑输了')
        exit(0)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页