Commit 5e56ac52 by BellCodeEditor

save project

parent cf39cb98
Showing with 32 additions and 14 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=250
self.attack=attack self.attack=40
self.max_hp = self.hp
def combat(self,enemy):
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
else:
info3 = enemy.name+"阵亡,游戏结束"
info = info1+info2+info3
print(info)
exit()
def upgrde(): class Player(Hero):
yase.level = yase.level+1 def __init__(self,name):
yase.hp = yase.hp+50 super().__init__(name)
yase.attack = yase.attack+4 self.hp = 200
self.attack = 50
player = Player("后羿")
print("玩家的血量值为:",player.hp)
print("玩家的攻击力为:",player.attack)
yase = Hero("语文老师",300,20)
print("语文老师的血量为:",yase.hp)
upgrde()
upgrde()
print("升级2次后,语文老师的血量为:",yase.hp)
# yase = Hero("语文老师",9999999999999999999999999999999999999999999999999999999999999999999999999999999999,9999999999999999999999999999999999999999999999999999999999999999999)
# houyi = Hero("数学老师",999999999999999999999999999999999999999999999999999999999999999999999999999,9999999999999999999999999999999999999999999999999999) # houyi = Hero("数学老师",999999999999999999999999999999999999999999999999999999999999999999999999999,9999999999999999999999999999999999999999999999999999)
# print("数学老师的血量为:",houyi.hp) # print("语文老师的血量为:",yase.hp)
\ No newline at end of file # print("数学老师的血量为:",houyi.hp
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