Commit a720b749 by BellCodeEditor

save project

parent 501958bb
Showing with 14 additions and 19 deletions
class Hero(object): class Hero(object):
def __init__(self,name): def __init__(self,name):
self.level=1
self.hp=3500
self.attack=388
self.name=name self.name=name
def upgarde(self): self.level=1
self.level+=1 self.hp=250
self.hp+=50 self.attack=40
self.attack+=4 self.max_hp=self.hp
def combat(self,enemy): def combat(self,enemy):
enemy.hp-=self.attack
inof1=self.name+'对'+enemy.name+'发起进攻' inof1=self.name+'对'+enemy.name+'发起进攻'
inof2='造成'+str(self.attack)+'点伤害' inof2='造成'+str(self.attack)+'点伤害'
enemy.hp-=self.attack
if enemy.hp>0: if enemy.hp>0:
inof3=enemy.name+'还剩下'+str(enemy.hp)+'血量' inof3=enemy.name+'还剩下'+str(enemy.hp)+'血量'
inof=inof1+inof2+inof3 inof=inof1+inof2+inof3
print(inof) print(inof)
else: else:
inof3=enemy.name+'已阵亡' inof3=enemy.name+'阵亡,游戏结束'
inof=inof1+inof2+inof3 inof=inof1+inof2+inof3
print(inof) print(inof)
exit() exit()
class Player(Hero): class Player(Hero):
def __init__(self,name): def __init__(self,name,hero_type):
super().__init__(name) super(Player,self).__init__(name)
self.hp=200 self.hp=200
self.attack=50 self.attack=50
player=Player('后羿') self.hero_type=hero_type
print('玩家的血量为:',player.hp) print('角色',self.name,'创建成功,英雄类型为:',self.hero_type)
print('玩家的攻击为:',player.attack) print('当前等级、血量、攻击力分别为:',self.level,self.hp,self.attack)
yase=Hero('亚瑟') houyi=Player('后羿','射手')
houyi=Hero('后羿','射手') yase=Hero('亚瑟')
print('角色'+houyi.name+'创建成功,英雄类型为:',houyi.hero_type) \ No newline at end of file
print('当前等级、血量、攻击力分别为:',houyi.level,houyi.hp,houyi.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