Commit 7d5ed80a by BellCodeEditor

save project

parent 365cf1e4
Showing with 13 additions and 6 deletions
# 英雄角色类 # 英雄角色类
class Hero(object): class Hero:
def __init__(self, name): def __init__(self, name):
self.level = 1 self.level = 1
self.hp = 3500 self.hp = 3500
self.attack = 388 self.attack = 388
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 + '发起攻击,'
...@@ -16,7 +16,14 @@ ...@@ -16,7 +16,14 @@
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,enemy,hero_type):
super().__init__(name)
self.hp=3400
self.attack=400
self.hero_type=hero_type
lx= Hero("李信") lx= Player("李信","战士")
houyi= Hero("后羿") yase= Hero("亚瑟")
lx.combat(houyi) #yase.combat(lx)
\ No newline at end of file print("角色"+lx.name+"创建成功,英雄类型为:",self.level,self.hp,self.attack)
\ 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