Commit 4db6ad57 by BellCodeEditor

save project

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