Commit af62df20 by BellCodeEditor

save project

parent dc4c04e5
Showing with 24 additions and 8 deletions
......@@ -4,10 +4,10 @@ class Hero():
self.level = 1
self.hp = 250
self.attack = 40
self.name = name
self.name =name
self.max_hp=self.hp
def combat(self,enemy): # 攻击
enemy.hp-=enemy.attack
enemy.hp-=self.attack
info1=self.name+"对" +enemy.name+"发起进攻,"
info2="造成"+str(self.attack)+"点伤害"
if enemy.hp>0:
......@@ -19,16 +19,32 @@ class Hero():
info=info1+info2+info3
print(info)
exit()
def cure(self):
self.hp=self.hp+60
if self.hp>self.max_hp:
self.hp=self.max_hp
print(self.name+"使用了治疗术,血量增加为:",60,"滴")
# yase = Hero("垭瑟")
# houyi= Hero("后羿")
# for i in range(7):
# yase.combat(houyi)
class Player(Hero):
def __init__(self,name):
def __init__(self,hero_type,name):
super(). __init__(name)
self.hp=200
self.attack=50
player=Player("后羿")
print(player.hp)
print(player.attack)
\ No newline at end of file
self.max_hp=self.hp
self.hero_type=hero_type
print('角色'+self.name+'创建成功,英雄类型为:',self.hero_type)
print('当前等级、血量、攻击力分别为:',self.level,self.hp,self.attack)
player=Player("射手","后羿")
computer=Hero("亚瑟")
player.combat(computer)
computer.combat(player)
player.cure()
computer.cure()
\ 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