Commit 4db6ad57 by BellCodeEditor

save project

parent d42693c7
Showing with 20 additions and 14 deletions
class Hero: class Hero:
def __init__(selt,name,hp,attack): def __init__(selt,name):
selt.level = 1 selt.level = 1
selt.hp = 250
selt.attack = 40
selt.name = name selt.name = name
selt.hp = hp
selt.attack = attack def combat(self,enemy):
def upgrade(selt): enemy.hp -= self.attack
selt.level = selt.level + 1 info1 = self.name + "对" + enemy.name + "发起攻击"
selt.hp = selt.hp + 200 info2 = "造成" + str(self.attack) + "伤害"
selt.attack = selt.attack + 100 if enemy.hp > 0:
yase = Hero("亚瑟",200,20) info3 = enemy.name + "剩余" + str(enemy.hp) + "血量"
houyi = Hero("后羿",150,15) info=info1+info2+info3
yase.upgrade() print(info)
houyi.upgrade() else:
print("亚瑟的血量:",yase.hp) info3 = enemy.name + "阵亡,游戏结束"
print("后羿的血量:",yase.hp) info=info1+info2+info3
\ No newline at end of file print(info)
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