Commit 36d3b777 by BellCodeEditor

save project

parent 1097f982
Showing with 22 additions and 9 deletions
class Hero:
def __init__(self,name,hp,attack):
def __init__(self,name):
self.level=1
self.name =name
self.hp= hp
self.attack= attack # attack:攻击
self.hp= 250
self.attack= 40 # attack:攻击
yase = Hero('亚瑟',800,10)
print("亚瑟的血量值为:",yase.hp)
print("亚瑟的攻击力为:",yase.attack)
houyi = Hero('后羿',600,15)
print("后羿的血量值为:",houyi.hp)
print("后羿的攻击力为:",houyi.attack)
def combat(self,enemy):
info1=self.name+'攻击了'+enemy.name+'。'
info2=enemy.name+'受到了'+self.attack+'点攻击。'
enemy.hp-=self.attack
if enemy.hp>0:
info3=enemy.name+'还剩'+enemy.hp-=self.attack+'滴血。'
info=info1+info2+info3
print(info)
else:
info3=enemy+'阵亡了。'
info=info1+info2+info3
print(info)
exit()
yase = Hero('亚瑟')
houyi = Hero('后羿')
yase.combat(houyi)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment