Commit fb15abc7 by BellCodeEditor

save project

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