Commit 7af263a8 by BellCodeEditor

auto save

parent 70850cf8
Showing with 86 additions and 0 deletions
class Hero:
def __init__(self,name,hp,level,attack):
self.name=name
self.hp=hp
self.level=level
self.attack=attack
def upgrade(self):
self.level+=1
self.hp+=50
self.attack+=4
yase=Hero("亚瑟",200,1,30)
houyi=Hero("后裔",250,1,27)
houyi.upgrade()
yase.upgrade()
#yase.hp=350
print("亚瑟的血量:",yase.hp)
print("后羿的血量:",houyi.hp)
import random
class Hero:
def __init__(self,name):
self.name=name
self.hp=250
self.level=1
self.attack=40
self.max_hp=self.hp
def combat(self,enemy): #普通攻击
enemy.hp-=self.attack
info1=self.name+"对"+enemy.name+"发起了攻击,"
info2="造成了"+str(self.attack)+"点伤害,"
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()
def cure(self):#普通治疗
self.hp+=60
if self.hp>self.max_hp:
self.hp=self.max_hp
print(self.name,"启动治疗术,血量增加了60,目前血量是:",self.hp)
class Player(Hero):
def __init__(self,name,type):
super().__init__(name)
self.hp=200
self.attack=50
self.herotype=type
self.max_hp=self.hp
print("英雄角色"+self.name+"创建成功,类型是:"+self.herotype)
print("当前角色的等级、血量、攻击力分别是:%d、%d、%d"%(self.level,self.hp,self.attack))
def cure(self):#普通治疗
blood=random.randint(30,50)
self.hp+=blood
if self.hp>self.max_hp:
self.hp=self.max_hp
print(self.name,"启动治疗术,血量增加了",blood,",目前血量是:",self.hp)
yase=Hero("亚瑟")
houyi=Player("后羿",'射手')
print("-"*50)
print(" 战斗开始")
while True:
choice=input("请选择释放英雄技能(1治疗/2攻击):")
if choice=="1":
houyi.cure()
elif choice=="2":
houyi.combat(yase)
elif choice=="q":
print("游戏结束!")
break
else:
print("请输入1或2")
continue
num=random.randint(1,3)
if num==1:
yase.cure()
else:
yase.combat(houyi)
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