Commit f05e8ef7 by BellCodeEditor

auto save

parent d11be80d
Showing with 31 additions and 16 deletions
# 英雄角色 class Hero: # 英雄
class Hero(object): def __init__(self, name): # 实例属性
def __init__(self, name): self.name = name
self.level = 1 self.level = 1
self.hp = 250 self.hp = 250
self.attack = 40 self.attack = 40
self.name = name self.max_hp = self.hp
def combat(self,enemy): # 攻击
def combat(self, enemy): # 攻击功能
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack enemy.hp -= self.attack
info1 = str(self.name)+"对"+str(enemy.name)+"发起攻击," if enemy.hp > 0:
info2 = "造成了"+str(enemy.attack)+"点伤害!" info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
if enemy.hp>0: info = info1+info2+info3
info3 = str(enemy.name)+"还剩"+str(enemy.hp)+"点血量!!!"
info=info1+info2+info3
print(info) print(info)
else : else:
info3 = str(enemy.name)+"阵亡,游戏胜利!!!" info3 = enemy.name+"阵亡,游戏结束"
info=info1+info2+info3 info = info1+info2+info3
print(info) print(info)
exit()
yase = Hero("垭瑟") class Player(Hero): # 玩家英雄
houyi= Hero("后羿") def __init__(self,name,hero_type):
super().__init__(name)
self.name = "后羿"
self.hp = 200
self.attack = 50
self.hero_type = hero_type
print("角色"+str(self.name)+"创建成功.英雄类型为:"+str(self.hero_type))
print("角色的等级、血量、攻击力分别为:"+str(self.level)+"、"+str(self.hp)+"、"+str(self.attack))
player = Player("后羿","射手")
print("玩家的血量值为:",player.hp)
print("玩家的攻击力为:",player.attack)
while True: while True:
xuanze=int(input("请按下“1”:")) xuanze=int(input("请按下“1”:"))
if xuanze==1: if xuanze==1:
yase.combat(houyi) yase.combat(yase)
if houyi.hp<=0: if houyi.hp<=0:
exit() exit()
\ 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