Commit df3e308c by BellCodeEditor

auto save

parent bd3ff508
Showing with 228 additions and 0 deletions
import random
class Hero(object):
def __init__(self, name): # 创建父类的属性
self.name = name
self.level = 1
self.hp = 250
self.attack = 40
self.max_hp = self.hp
self.feel = 1
def cure(self): # 定义治疗
blood=random.randint(30,50)
if self.hp<self.max_hp:
if self.hp+blood<=self.max_hp:
print(self.name+"使用了治疗,血量增加:",blood)
self.hp=self.hp+blood
print("目前的血量为:",self.hp)
else:
print(self.name+"使用了治疗,血量增加:",self.max_hp-self.hp)
self.hp=self.max_hp
print("目前的血量为:",self.hp)
else:
print(self.name,"已是满血,治疗无效,目前血量:",self.hp)
def combat(self, enemy): # 定义普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
else:
enemy.feel=0
info3 = enemy.name+"阵亡"
info = info1+info2+info3
print(info)
class Player(Hero):
def __init__(self,hero_type,name): #创建子类继承父类
super().__init__(name)
self.hp = 200
self.attack = 50
self.max_hp = self.hp
self.hero_type = hero_type
self.feel = 1
print("角色",self.name,"创建成功,英雄类型为:",self.hero_type) #介绍玩家角色
print("当前等级:",self.level,", 血量:",self.hp,", 攻击力为:",self.attack)
print(" 请创建玩家角色档案") #玩家自创角色档案
name=input("名称:")
name=" <"+name+"> "
type=input("类型:")
houyi = Player(type, name)
yase = Hero(" <亚瑟> ") #创建电脑角色
erlangshen=Hero(" <二郎神> ")
print("-"*30)
while True:
if houyi.feel==1:
if yase.feel==1:
#玩家出招
an1=input("请输入 1(攻击)/2(治疗)/q(退出游戏):")
if an1=="1":
if erlangshen.feel==1:
ch1=input("请输入 1(打 <亚瑟> )/2(打 <二郎神> )/q(返回):")
print("-"*30)
if ch1=="1":
houyi.combat(yase)
print("-"*30)
elif ch1=="2":
houyi.combat(erlangshen)
print("-"*30)
elif ch1=="q":
continue
else:
continue
else:
ch1=input("请输入 1(打 <亚瑟> )/q(返回):")
print("-"*30)
if ch1=="1":
houyi.combat(yase)
print("-"*30)
elif ch1=="q":
continue
else:
continue
elif an1=="2":
print("-"*30)
houyi.cure()
print("-"*30)
elif an1=="q":
print(houyi.name,"逃跑了,已退出游戏")
break
else:
print("-"*30)
continue
#电脑角色<亚瑟>出招
if yase.feel==1:
if yase.hp<yase.max_hp:
if erlangshen.feel==1:
an2=random.randint(1,3)
if an2==1:
yase.cure()
print("-"*30)
elif an2==2:
yase.combat(houyi)
print("-"*30)
else:
yase.combat(erlangshen)
print("-"*30)
else:
an2=random.randint(1,2)
if an2==1:
yase.cure()
print("-"*30)
elif an2==2:
yase.combat(houyi)
print("-"*30)
else:
if erlangshen.feel==1:
an2=random.randint(1,2)
if an2==1:
yase.combat(houyi)
print("-"*30)
else:
yase.combat(erlangshen)
print("-"*30)
else:
yase.combat(houyi)
print("-"*30)
#电脑角色<二郎神>出招
if erlangshen.feel==1:
an3=random.randint(0,1)
if an3==1:
if erlangshen.hp<erlangshen.max_hp:
if yase.feel==1:
ch3=random.randint(1,2)
if ch3==1:
erlangshen.combat(houyi)
erlangshen.cure()
print("-"*30)
else:
erlangshen.combat(yase)
erlangshen.cure()
print("-"*30)
else:
erlangshen.comAcure(houyi)
print("-"*30)
else:
if yase.feel==1:
ch3=random.randint(1,2)
if ch3==1:
erlangshen.combat(houyi)
print("-"*30)
else:
erlangshen.combat(yase)
print("-"*30)
else:
erlangshen.combat(houyi)
print("-"*30)
else:
print(" <二郎神> 本回合在蓄力")
print("-"*30)
else:
if erlangshen.feel==0:
print("游戏结束,",houyi.name,"胜利")
exit()
else:
#玩家出招
an1=input("请输入 1(攻击)/2(治疗)/q(退出游戏):")
if an1=="1":
ch1=input("请输入 1(打 <二郎神> )/q(返回):")
print("-"*30)
if ch1=="1":
houyi.combat(erlangshen)
print("-"*30)
elif ch1=="q":
continue
else:
continue
elif an1=="2":
print("-"*30)
houyi.cure()
print("-"*30)
elif an1=="q":
print(houyi.name,"逃跑了,已退出游戏")
break
else:
print("-"*30)
continue
#电脑角色<二郎神>出招
if erlangshen.feel==1:
an3=random.randint(0,1)
if an3==1:
if erlangshen.hp<erlangshen.max_hp:
erlangshen.combat(houyi)
erlangshen.cure()
print("-"*30)
else:
erlangshen.combat(houyi)
print("-"*30)
else:
print(" <二郎神> 本回合在蓄力")
print("-"*30)
else:
#判定游戏结果
if yase.feel==1:
if erlangshen.feel==0:
print("游戏结束,",yase.name,"胜利")
exit()
else:
print("游戏结束,玩家",houyi.name,"阵亡,",yase.name,erlangshen.name,"存活")
print()
exit()
else:
print("游戏结束,",erlangshen.name,"胜利")
exit()
\ 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