Commit 3ab6bdd1 by BellCodeEditor

save project

parent dfb5d1b6
Showing with 31 additions and 0 deletions
class Hero(object):
def __init__(self, name):
self.level = 1
self.hp = 250
self.attack = 40
self.name = name
def combat(self,enemy): # 攻击
enemy.hp-=self.attack
infor1=self.name+'对'+enemy.name+'发起进攻,'
infor2='造成了'+str(self.attack)+'伤害'
infor3=enemy.name+'还剩下'+str(enemy.hp)+'血量'
if enemy.hp>0:
info=infor1+infor2+infor3
print(infor1+infor2+infor3)
else:
info=infor1+infor2+infor3+enemy.name+'阵亡'
print('游戏结束')
exit()
class Player(Hero):
def __init__(self,name,hp,attack,hero_type):
super().__init__(name)
self.hp = hp
self.attack =attack
self.hero_type=hero_type
print('角色'+self.name+'创建成功,英雄类型为:',self.hero_type)
print('当前等级、血量、攻击力分别为:',self.level,self.hp,self.attack)
player=Player('后羿',200,30,'射手')
player2=Player('亚瑟',250,40,'战士')
# print('玩家血量为:',player.hp)
# print('玩家攻击力为:',player.attack)
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