Commit 82575b8f by BellCodeEditor

auto save

parent db2ed9b7
Showing with 36 additions and 12 deletions
class Hero:
def __init__(self,name,level,HP,attack):
def __init__(self,name):
self.name=name
self.level=level
self.HP=HP
self.attack=attack
def upgrade(self):
self.level+=1
self.HP+=50
self.attack+=4
yase=Hero("亚瑟",1,300,20)
yase.upgrade()
print(yase.level)
\ No newline at end of file
self.level=1
self.HP=250
self.attack=40
# def upgrade(self):
# self.level+=1
# self.HP+=50
# self.attack+=4
def combat(self,enemy):
enemy.HP-=self.attack
info1=self.name+"对"+enemy.name+"发起进攻\n"
info2="造成了"+str(self.attack)+"点伤害\n"
if enemy.HP>0:
info3=enemy.name+"剩余血量为"+str(enemy.HP)
info=info1+info2+info3
print(info)
else:
info3=enemy.name+"阵亡"
info=info1+info2+info3
print(info)
exit()
print("-"*30)
class Player(Hero):
def __init__(self,name,hero_type):
super(Player,self).__init__(name)
self.HP=200
self.attack=50
self.hero_type=hero_type
print("角色"+self.name+"已经创建成功"+"角色职业为"+self.hero_type)
print("角色"+self.name+"的等级、血量、攻击力分别为:"+str(self.level)+"、"+str(self.HP)+"、"+str(self.attack)+"、")
houyi=Player("后羿","射手")
# print(yase.HP)
# print(houyi.HP)
yase.combat(houyi)
houyi.combat(yase)
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