决战紫禁之巅 西门吹雪和叶孤城
属性:
name 玩家的名字
blood 玩家血量
方法:
tong()捅对方一刀,对方掉10滴血
kanren()看对方一刀,对方掉15滴血
chiyao()吃一颗药,补10滴血
__str__打印玩家状态
class Role():
def __init__(self, name, hp):
"""
构造初始化函数
:param name: 角色名字
:param hp: 角色血量
"""
self.name = name
self.hp = hp
pass
def tong(self, enemy):
enemy.hp -= 10
info = '【%s】捅了【%s】一刀。' % (self.name, enemy.name)
print(info)
pass
def kanren(self, enemy):
enemy.hp -= 15
info = '【%s】砍了【%s】一刀。' % (self.name, enemy.name)
print(info)
pass
def chiyao(self):
self.hp += 10
info = '【%s】吃了一颗药,回复了10滴血。' % self.name
print(info)
pass
def __str__(self):
return '%s还剩下%s的血量' % (self.name, self.hp)
pass
xmcx = Role('西门吹雪', 100)
ygc = Role('叶孤城', 100)
while True:
if xmcx.hp<=0 or ygc.hp<=0:
break
xmcx.tong(ygc) # 西门吹雪捅叶孤城一刀
print(ygc)
print(xmcx)
ygc.kanren(xmcx)
print(ygc)
print(xmcx)
xmcx.chiyao()
print(ygc)
print(xmcx)
time.sleep(1)
pass
print('----对战结束----')