Commit d3c02b9e by BellCodeEditor

save project

parent f59eee5e
Showing with 11 additions and 8 deletions
# 英雄角色类 # 英雄角色类
class Hero(object): class Hero(object):
def __init__(self, name): def __init__(self, name,hero_type):
self.level = 1 self.level = 1
self.hp = 250 self.hp = 250
self.attack = 50 self.attack = 50
self.name = name self.name = name
def combat(self,enemy): # 攻击 def combat(self,enemy): # 攻击
enemy.hp -= self.attack enemy.hp -= self.attack
info1 = self.name + '对' + enemy.name + '发起攻击,' info1 = self.name + '对' + enemy.name + '发起攻击,'
...@@ -15,8 +14,12 @@ class Hero(object): ...@@ -15,8 +14,12 @@ class Hero(object):
else: else:
info3 = enemy.name + '还剩下' + str(enemy.hp) + '点生命值' info3 = enemy.name + '还剩下' + str(enemy.hp) + '点生命值'
print(info1 + info2 + info3) print(info1 + info2 + info3)
class Player(Hero):
def __init__(self, name,hero_type):
yase = Hero("垭瑟") super().__init__(name,hero_type)
houyi= Hero("后羿") self.hp = 350
yase.combat(houyi) self.attack = 40
\ No newline at end of file self.hero_type=hero_type
print("角色"+self.name+"创建成功,英雄类为"+hero_type)
print("当前等级,生命,攻击力,分别为",self.level,self.hp,self.attack)
houyi = Player('后羿','射手')
\ 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