class Person: #声明一个类标签:10.3,name,hp,dog,大战,person,人狗,self,ad From: https://www.cnblogs.com/zhh0125/p/16666910.html
def __init__(self,name,hp,ad,sex,job):
'''初始化函数'''
self.name=name
self.hp=hp
self.ad=ad
self.sex=sex
self.job=job
def attack(self,dog):
'''人打狗,狗掉血'''
dog.hp=dog.hp-self.sd
print('%s攻击了%s,%s掉了%s血,还剩%s血'%(
self.name,
dog.name,
dog.name,
self.ad,
dog.hp ))
class Dog:#声明一个类
def __init__(self,name,kind,hp,sd):
'初始化函数'
self.name=name
self.hp=hp
self.ad=ad
self.kind=kind
def bite(self,person) :
person.hp-=self.ad
print('%s咬了%s,%s掉了%s血,还剩%s血'%(
self.name,
person.name,
person.name,
self.ad,
person.hp
))
zhangsan=Person('zhangsan',200,40,'男','射手')
lisi=Person('lisi',400,20,'男','战士')
dog1=Dog('旺财','小土狗',20000,40)
dog1=Dog('二哈','哈士奇',20000,40)
dog1.bite(zhangsan)
lisi.attack(dog2)