Commit fb15abc7 by BellCodeEditor

save project

parent f9c07074
Showing with 24 additions and 23 deletions
class Hero():
def __init__(self,name,hp,attack):
def __init__(self,name):
self.level=1
self.hp=hp
self.attack=attack
self.hp=250
self.attack=40
self.name=name
def upgrade(name):
name.level=name.level+1
name.hp=name.hp+50
name.attack=name.attack+4
yase=Hero('亚瑟',300,30)
houyi=Hero('后羿',250,23)
zhugeliang=Hero('诸葛亮',270,40)
yase.upgrade()
houyi.upgrade()
zhugeliang.upgrade()
print(yase.name+'的血量为'+str(yase.hp))
print(yase.name+'的攻击为'+str(yase.attack))
print(yase.name+'的等级为'+str(yase.level))
print(houyi.name+'的血量为'+str(houyi.hp))
print(houyi.name+'的攻击为'+str(houyi.attack))
print(houyi.name+'的等级为'+str(houyi.level))
print(zhugeliang.name+'的血量为'+str(zhugeliang.hp))
print(zhugeliang.name+'的攻击为'+str(zhugeliang.attack))
print(zhugeliang.name+'的等级为'+str(zhugeliang.level))
\ No newline at end of file
def combat(self,enemy):
enemy.hp-=self.attack
info1=self.name+"对"+enemy.name
info2="发起攻击,"+"造成"+str(self.attack)+"点伤害"
info3=enemy.name+"还剩"+str(enemy.hp)+"点血量"
if enemy.hp>0:
info=info1+info2+info3
print(info)
else:
info4=enemy.name+"阵亡"
info=info1+info2+info4
print(info)
#def upgrade(name):
# name.level=name.level+1
# name.hp=name.hp+50
# name.attack=name.attack+4
yase=Hero('亚瑟')
houyi=Hero('后羿')
zhugeliang=Hero('诸葛亮')
Hero.combat(yase,zhugeliang)
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