升级游戏的

class Game():

    def __init__(self, name, sex, hp, exp):
        self.name = name
        self.sex = sex
        self.hp = hp
        self.exp = exp

    def showhp(self):
        self.hp -= 20
        if self.hp <= 0:
            print('your hero is dead...')
        else:
            pass
        return self.hp

    def showexp(self):
        self.exp += 50
        if self.exp == 50:
            print('你升级了')
        else:
            pass
        return self.exp


if __name__ == '__main__':
    Button = str(input('是否开始游戏 y/n '))
    if Button == 'y':
        Player1 = Game(name='Little Boy', sex='male', hp=100, exp=0)
        for i in range(3):
            Player1.showhp()
        for i in range(5):
            Player1.showexp()
    else:
        pass
    print('你剩余的生命值为')
    print(Player1.hp)

 

你可能感兴趣的:(游戏,python,开发语言)