You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
9.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import random
import sys
import Character
# 游戏初始化
Round = 1
Hero = Character.Hero
bag = ["","","铁骑","暴怒"]
# 事件函数
# 战斗
def fight(n=True):
if n:
# 创建一个怪物
print("突然正前方跳出一个身影,似乎跃跃欲试")
print("战斗开始!")
monster = Character.Hero(50, 8, 8, 8)
else:
# 创建一个BOSS
print("你打开了这个地牢最后的房间,你发誓再也不想看到这种生物")
print("战斗开始!")
monster = Character.Hero(150, 13, 12, 10)
# 战斗前角色初始化
hero.nuqi = 0
monster.nuqi = 0
jiu, tieji = False, False
tieji_num = 0
while True:
print(f"""\n我:\tHp{hero.hp}\t\t敌:\tHp{monster.hp}\n\t怒气{hero.nuqi}\t\t\t怒气{monster.nuqi}""",end="")
# 主角进行操作
dongZuo = input("""\n1.攻击\t\t2.怒击\n3.道具\t\t4.逃跑\n""")
if dongZuo == '1':
damage = hero.attack(monster.min, jiu, tieji)
jiu = False
if tieji_num == 1:
tieji = False
else:
tieji_num += 1
if damage:
monster.hp -= damage
monster.nuqi += 10
monster.nuqi = min(monster.nuqi, 100)
print(f"我方攻击成功命中,造成{damage}点伤害")
else:
print("敌方闪避掉了")
print(f"敌方剩余血量:{max(0, monster.hp)}")
elif dongZuo == '2':
# 判断怒气是否达到100
if hero.nuqi < 100:
print("怒气不足100请重新选择")
continue
else:
damage = hero.enragedAttack(monster.min, jiu, tieji)
jiu = False
if tieji_num == 1:
tieji = False
else:
tieji_num += 1
if damage:
monster.hp -= damage
print(f"我方愤怒一击成功命中,造成{damage}点伤害")
else:
print("敌方闪避掉了")
print(f"敌方剩余血量:{max(0, monster.hp)}")
hero.nuqi = 0
elif dongZuo == '3':
if not hero.bag:
print("您的背包空空如也")
continue
else:
for j, k in enumerate(hero.bag,start=1):
print(f"{j}.{k} ",end='')
a = int(input("\n请选择你要使用的道具"))-1
print(f"您使用了{hero.bag[a]}")
if hero.bag[a] == "":
hero.hp = min(hero.max_hp, hero.hp + 50)
print("恢复50点hp")
elif hero.bag[a] == "":
jiu = True
print("下次攻击伤害增加")
elif hero.bag[a] == "铁骑":
tieji = True
print("下两次攻击必中")
elif hero.bag[a] == "暴怒":
hero.nuqi = 100
print("怒气增加100")
del hero.bag[a]
elif dongZuo == '4':
if n:
if hero.run(monster.min):
print("逃跑成功!")
break
else:
print("被敌人发现了,逃跑失败!")
else:
print("你被一个巨大的身影拦住,已无路可走!")
else:
print('您输入的指令有误,请重新输入!')
continue
# 奖励系统
if monster.hp <= 0:
print("*** 恭喜您取得了战斗胜利! ***")
if not n:
print("游戏胜利!")
sys.exit(0)
print("请您选择奖励:\t1.力量+1\t2.敏捷+1\t3.智力+1")
while True:
ap = input()
if ap == '1':
hero.li += 1
break
elif ap == '2':
hero.min += 1
break
elif ap == '3':
hero.zhi += 1
break
else:
print('您输入的指令有误,请重新输入!')
break
# 怪物进行操作
if monster.nuqi < 100:
damage = monster.attack(hero.min)
if damage:
hero.hp -= damage
hero.nuqi += 10
hero.nuqi = min(hero.nuqi, 100)
print(f"敌方成功命中,造成{damage}点伤害")
else:
print("我方闪避掉了")
print(f"我方剩余血量:{max(0, hero.hp)}")
else:
damage = monster.enragedAttack(hero.min)
if damage:
hero.hp -= damage
print(f"敌方愤怒一击成功命中,造成{damage}点伤害")
else:
print("我方闪避掉了")
print(f"我方剩余血量:{max(0, hero.hp)}")
monster.nuqi = 0
if hero.hp <= 0:
print("玩家死亡,你永远留在立地牢中!\n*** 游戏结束 ***")
sys.exit(0)
print("************************************")
# 恢复
def restore():
rd = random.random()
if rd < 0.5:
add_hp = hero.zhi + 15
hero.hp = min(hero.max_hp, hero.hp + add_hp)
print(f"前方有一个泉水,你喝了一口感觉好多了\n血量恢复了{add_hp}")
else:
add_hp = hero.zhi + 10
hero.hp = min(hero.max_hp, hero.hp + add_hp)
print(f"你遇到了一个篝火还没燃烧干净,于是你坐下来休息了一会儿\n血量恢复了{add_hp}")
# 陷阱
def trap():
rd = random.random()
if rd < 0.5:
sub_hp = 30 - hero.min
hero.hp = max(0, hero.hp - 25)
print(f"下楼梯时你突然踩空了,好在没有摔的太惨\n血量-{sub_hp}")
else:
sub_hp = 40 - hero.min
hero.hp = max(0, hero.hp - 35)
print(f"侧面墙壁中突然飞出几只箭,还好你反应快躲了过去,但还是被擦伤\n血量-{sub_hp}")
if hero.hp <= 0:
print("玩家死亡,你永远留在立地牢中!\n*** 游戏结束 ***")
sys.exit(0)
# 诅咒
def curse():
rd = random.random()
if rd < 0.33:
print("忽然身上长了一个脓包,给你的行动带来了不便\n敏捷-1")
hero.min -= 1
elif rd < 0.66:
print("你看到了一些影子,感觉大脑昏昏沉沉,没有思考太多继续前进\n智力-1")
hero.zhi -= 1
else:
print("一只不知名的虫子咬了你的手臂一口,你感觉使不上劲\n力量-1")
hero.li -= 1
# 祝福
def blessing():
rd = random.random()
if rd < 0.33:
print("你遇到了一个精灵,他给了你一瓶绿色的药水,你选择毫不犹豫地喝了下去\n敏捷+1")
hero.min += 1
elif rd < 0.66:
print("突然你脑子里面闪过一个灵感\n智力+1")
hero.zhi += 1
else:
print("你捡起前面的哑铃,做了一组力量训练,感觉身体变强壮了\n力量+1")
hero.li += 1
# 道具
def item():
# 在列表里面随机抽取一个元素
dj = random.choice(bag)
hero.bag.append(dj)
print(f"你获得了一个 {dj}")
while True:
zy = input("""请选择英雄
1.战士
2.魔法师
3.骑士
""")
if zy == '1':
zy = '战士'
hero = Hero(150, 10, 10, 10,bag=["",""])
break
elif zy == '2':
zy = '魔法师'
hero = Hero(80, 8, 18, 12)
break
elif zy == '3':
zy = '骑士'
hero = Hero(100, 15, 10, 14)
break
else:
print("输入错误请重新输入!")
while True:
sl = input("""
1.向左走
2.向右走
3.向前走
4.查看状态
(请输入序号)
""")
# Boos战
if Round == 20:
fight(False)
# 随机事件,不同权重
sj = random.random()
if sl == '1':
# 侧重回血、陷阱
if sj < 0.25:
restore()
elif sj < 0.5:
trap()
elif sj < 0.65:
blessing()
elif sj < 0.75:
curse()
elif sj < 0.9:
item()
else:
fight()
elif sl == '2':
# 侧重诅咒、增益
if sj < 0.25:
blessing()
elif sj < 0.5:
trap()
elif sj < 0.65:
curse()
elif sj < 0.75:
trap()
elif sj < 0.9:
item()
else:
fight()
elif sl == '3':
# 侧重道具、战斗
if sj < 0.25:
fight()
elif sj < 0.5:
item()
elif sj < 0.65:
blessing()
elif sj < 0.75:
curse()
elif sj < 0.9:
restore()
else:
trap()
elif sl == '4':
# 查看当前状态
print(f"""
职业:{zy}
血量:{hero.hp}
力量:{hero.li}
敏捷:{hero.min}
智力:{hero.zhi}
背包:{hero.bag}
""")
else:
print('您输入的指令有误,请重新输入!')
Round += 1