from time import sleep class Person: role= 'people' def __init__(self,name,attack,blood,defense,weapon=None): self.name= name self.attack=int(attack) self.blood=int(blood) self.defense=defense self.weapon=weapon def attack_start(self,dog_name): if self.weapon == None: dog_name.blood -= self.attack print(self.name+'攻击了%s,'%dog_name.name) else: dog_name.blood -= self.attack print('%s使用%s砍了%s一刀'%(self.name,self.weapon,dog_name.name)) def equip_weapon(self,weapon_name): self.blood += 1000 self.attack+= 50 self.weapon = weapon_name.name print('%s捡到了%s'%(self.name,weapon_name.name)) class Dog: role='dog' def __init__(self,name,kind,aggresivity,defence,blood): self.name=name self.kind=kind self.aggresivity=aggresivity self.defence=defence self.blood=blood def bite(self,person): person.blood -= self.aggresivity print('%s咬了%s一口'%(self.name,person.name)) class weapon: def __init__(self,name,add_attack,add_blood): self.name=name self.add_attack=add_attack self.add_flood=add_blood print('爆出了一件%s'%self.name) print('人狗大战即将开始') for i in range(10,-1,-1): print(i) sleep(0.6) print('开始') alex = Person('alex',10,500,50) teddy = Dog('teddy','teddy',100,50,90) sleep(0.6) alex.attack_start(teddy) sleep(0.6) print(teddy.blood)#blood血液 flood 洪水 sleep(0.6) teddy.bite(alex) sleep(0.6) print(alex.blood) sleep(0.6) wujin=weapon('无尽之刃',10,100) sleep(0.6) alex.equip_weapon(wujin) sleep(0.6) alex.attack_start(teddy) sleep(0.6) print(teddy.blood) print('未完待续')