class Role:
def init(self,name,hp):
‘’’
构造初始化函数
:param name:角色名字
:param hp: 血量
‘’’
self.name=name
self.hp=hp
pass
def tong(self,enemy):
‘’’
捅一刀
:param enemy:敌人
:return:
‘’’
enemy.hp-=10
info=’【%s】捅了【%s】一刀’%(self.name,enemy.name)
print(info)
pass
def kanren(self, enemy):
‘’’
砍一刀
:param enemy:敌人
:return:
‘’’
enemy.hp -=15
info = ‘【%s】砍了【%s】一刀’ % (self.name, enemy.name)
print(info)
pass
def chiyao(self,):
‘’’
吃药
:param enemy:
:return:
‘’’
self.hp+=10
info = ‘【%s】吃了一颗补血药,增加了十滴血’% (self.name)
print(info)
pass
def str(self):
return ‘%s 还剩下 %s 的血量’%(self.name,self.hp)
xmcx=Role(‘西门吹雪’,100)
ygc=Role(‘叶孤城’,100)
while True:
if xmcx.hp<=0 or ygc.hp<=0:
break
xmcx.tong(ygc)
print(xmcx)
print(ygc)
print(‘’)
ygc.tong(xmcx)
print(xmcx)
print(ygc)
print('’)
xmcx.chiyao()
print(xmcx)
print(ygc)
print(‘’)
ygc.tong(xmcx)
print(xmcx)
print(ygc)
print('’)
xmcx.kanren(ygc)
print(xmcx)
print(ygc)
print(‘’)
ygc.kanren(xmcx)
print(xmcx)
print(ygc)
print('’)
pass
print(‘对战结束…’)