Commit 9e6c2d6e by BellCodeEditor

save project

parent 5894d29e
Showing with 21 additions and 11 deletions
class Hero: class Hero:
def __init__(self,name,hp,attack): def __init__(self,name):
self.level=1 self.level=1
self.name=name self.name=name
self.hp=hp self.hp=300
self.attack=attack self.attack=60
def upgrade(self): def combat(self,enemy):
self.level=self.level+1 info1 = self.name+enemy.name+"发起进攻"
self.hp = self.hp + 50 info2 = "早成"+str(self.attack)+"点伤害"
self.attack = self.attack+4 if enemy.hp>0:
liudan = Hero("榴弹",300,20) info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
liudan.upgrade() info = info1+info2+info3
print("等级为:",liudan.level) print(info)
\ No newline at end of file else:
info3 = enemy.name+"阵亡游戏结束"
info = info1+info2+info3
print(info)
exit()
liudan = Hero("亚瑟")
houyi = Hero("AI")
liudan.combat(liudan)
\ 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