Commit b6a433de by BellCodeEditor

save project

parent 379e9f74
Showing with 22 additions and 23 deletions
class Hero: # 英雄 # 英雄角色
def __init__(self, name): # 实例属性 class Hero():
self.name = name def __init__(self, name):
self.level = 1 self.level = 1
self.hp = 250 self.hp = 250
self.attack = 40 self.attack = 40
self.max_hp = self.hp self.name = name
def combat(self, enemy): # 攻击功能 def combat(A,B): # 攻击
info1 = self.name+"对"+enemy.name+"发起进攻," B.hp=B.hp-A.attack
info2 = "造成"+str(self.attack)+"点伤害," print(A.name+"对"+B.name+"发起进攻,造成"+str(A.attack)+"伤害,")
enemy.hp -= self.attack if B.hp>0:
if enemy.hp > 0: print(B.name+"还剩下"+str(B.hp)+"点血")
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
else: else:
info3 = enemy.name+"阵亡,游戏结束" print(B.name+"被"+A.name+"击败")
info = info1+info2+info3
print(info)
exit() exit()
class Player(): # 玩家英雄 yase = Hero("垭瑟")
def __init__(self,name): houyi= Hero("后羿")
??? class.player(Hero):
def __init__(self, name):
super().__init__(level,name)
self.hp = 100
self.attack = 400
player = Player("后羿") player = Player("后羿")
print("玩家的血量值为:",player.hp) computer = Hero("亚瑟")
print("玩家的血量为:",player.hp)
print("玩家的等级为:",player.level)
print("玩家的攻击力为:",player.attack) print("玩家的攻击力为:",player.attack)
print("玩家的名称为:",player.name)
\ 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