[python]代码库
import random
import time as t
num = 1
if True:
if True:
if True:
while num <= 5:
if num == 1:
print("第一关:猛兽恶战")
#猛兽初始值
camOnespawA = random.randint(1,3)
#猛兽力量
camOnespawS = camOnespawA * 2
#猛兽血量
camOnespawL = camOnespawA * 10
#玩家初始值
camOnepeopA = random.randint(1,4)
#玩家力量
camOnepeopS = camOnepeopA * 2
#玩家血量
camOnepeopL = camOnepeopA * 11
#提示玩家
print("你的血量:" + str(camOnepeopL))
print("你的力量:" + str(camOnepeopS))
t.sleep(0.4)
print("猛兽:-未知-")
t.sleep(2)
#提示玩家
print("你已经和猛兽厮杀起来!")
#随机状态
camOneState = random.randint(0,1)
#打斗次数
camOneT = 0
while camOneState <= 1:
if camOnespawL <= 0: #判断猛兽的血量是否低于0
print("你战胜了猛兽!!")
num += 1
break #跳到第二关
elif camOnepeopL <= 0: #判断玩家的血量是否低于0
print("你被猛兽打死了...")
elif camOnepeopS <= 0: #判断玩家的力量是否低于1
print("你没有力气了...")
print("可想而知...")
if camOneState == 0: #猛兽打玩家
print("猛兽向你发起了进攻!") #提示玩家
t.sleep(0.5) #时间停顿
if camOneT == 0:
print("猛兽给了你一巴掌!")
t.sleep(0.4)
print("又踹了你一脚!")
print("你扣了" + str(4) + "血量")
camOnepeopL -= 4 #扣血量
camOneT += 1 #加次数
t.sleep(1)
camOneState = random.randint(0,1) #重新随机状态
else:
print("猛兽又做出了出拳的动作!")
ansCamOneExer = int(input("(躲避:1;回击:2):")) #问玩家
#print("猛兽给了你一拳!")
while ansCamOneExer >= 3:
#动作
ansCamOneExer = int(input("(躲避:1;回击:2):"))
if ansCamOneExer == 1:
#躲避
#再次随机躲避状态
comOneStateE = random.randint(0,2)
if comOneStateE == 0:
print("你躲过了攻击")
elif comOneStateE == 1:
print("你躲过了攻击")
t.sleep(0.6)
print("可又被打了一拳!")
#随机一个被扣掉的血量
comOneKoL = random.randint(1,camOnespawS)
t.sleep(0.7)
#提示玩家
print("你扣了" + str(comOneKoL) + "血量")
camOnepeopL -= comOneKoL
elif comOneStateE == 2:
print("你回击了一拳")
comOneKoS = random.randint(1,3)
print("可你还是减少了" + str(comOneKoS) + "力量")
camOnepeopS -= comOneKoS #减力量
elif ansCamOneExer == 2:
#回击
if camOnepeopS < camOnespawS:
print("你回击了一拳,可是力量不足,被扣了" + str(1) + "血量")
camOnepeopL -= comOneKoL #减力量
else:
print("")
elif camOneState == 1:
#玩家进攻
print("你向猛兽发起了进攻!") #提示玩家
#随机状态
comOnepeopState = random.randint(0,1)
if comOnepeopState == 0:
#判断次数是否小于1(改变语句)
if camOneT == 0:
comOnespawKoL = random.randint(0,camOnepeopS)
print("你给了猛兽一拳!猛兽被扣了" + str(comOnespawKoL) + "血量")
camOnespawL -= comOnespawKoL
t.sleep(1)
else: #否则
comOnespawKoL = random.randint(0,camOnepeopS)
print("你又给了猛兽一拳!猛兽被扣了" + str(comOnespawKoL) + "血量")
camOnespawL -= comOnespawKoL
t.sleep(1)
elif comOnepeopState == 1: #同理
if camOneT == 0:
comOnespawKoL = random.randint(0,camOnepeopS)
print("你踹了猛兽一脚!猛兽被扣了" + str(comOnespawKoL) + "血量")
camOnespawL -= comOnespawKoL #减血量
t.sleep(1)
else:
comOnespawKoL = random.randint(0,camOnepeopS)
print("你拿起木棒打了猛兽一棒!猛兽被扣了" + str(comOnespawKoL) + "血量")
camOnespawL -= comOnespawKoL #减血量
t.sleep(1)
t.sleep(0.4)
camOneT += 1 #加次数
t.sleep(1)
#继续随机状态
camOneState = random.randint(0,1)
elif num == 2:
#第二关
#开场白
print("你再次安然无恙的走了1天...")
t.sleep(0.7)
print("也再次被3条毒蛇盯上了...")
t.sleep(0.7)
print("今天黄昏的时候,你正搭着帐篷,3条毒蛇突然向你发起了进攻...")
t.sleep(1)
print("第二关:毒蛇缠绕")
#设置血量和力量
#毒蛇1
comTwospawA1 = random.randint(1,3)
comTwospawS1 = comTwospawA1 * 2
comTwospawL1 = comTwospawA1 * 3
#毒蛇2
comTwospawA2 = random.randint(1,3)
comTwospawS2 = comTwospawA2 * 2
comTwospawL2 = comTwospawA2 * 3
#毒蛇3
comTwospawA3 = random.randint(1,3)
comTwospawS3 = comTwospawA3 * 2
comTwospawL3 = comTwospawA3 * 3
#玩家
comTwopeopA = random.randint(2,5)
comTwopeopS = comTwopeopA * 2
comTwopeopL = comTwopeopA * 5
#毒蛇的平均力量和血量
comTwospawTegeS = int((comTwospawS1 + comTwospawS2 + comTwospawS3) / 3)
comTwospawTegeL = int((comTwospawL1 + comTwospawL2 + comTwospawL3) / 3)
print("你的血量:" + str(comTwopeopL))
print("你的力量:" + str(comTwopeopS))
print("毒蛇平均血量:" + str(comTwospawTegeL))
print("毒蛇平均力量:-未知-")
#毒蛇列表
comTwospawlen = ['-','-','-']
t.sleep(1)
camTwoState = random.randint(0,1)
#打斗次数
camTwoT = 0
while camOneState <= 1:
if len(comTwospawlen) <= 0 or comTwospawTegeL <= 0:
print("你战胜了3条毒蛇!")
num += 1 #加关卡
break #退出循环
elif comTwopeopL <= 0:
print("你被3条毒蛇咬死了...") #KO
if camTwoState == 0:
#毒蛇进攻
print("毒蛇向你发起了进攻!")
#提示玩家
print("一条毒蛇向你袭来!")
#提问
ansComTwoExer = int(input("(躲避:1;拿棍打:2):"))
if ansComTwoExer == 1:
#躲避
comTwoStateE = random.randint(0,1) #再次随机状态
if comTwoStateE == 0:
#直接躲过
print("你躲过了毒蛇的进攻")
#再次随机状态
camTwoState = random.randint(0,1)
elif comTwoStateE == 1:
#刮伤了一点点
print("你躲过了毒蛇的进攻")
t.sleep(0.3)
comTwopeopKoL = random.randint(0,comTwospawTegeS)
print("可还是被刮伤了一点点,你被扣了" + str(comTwopeopKoL) + "血量")
comTwopeopL -= comTwopeopKoL #扣血量
elif ansComTwoExer == 2:
#拿棍打
comTwoStateE = random.randint(0,4) #随机五次状态
if comTwoStateE == 0 or comTwoStateE == 1:
comTwopeopKoL = random.randint(0,comTwospawTegeS)
print("你拿木棍打了一棒,可是没打到,还被扣了" + str() + "血量")
comTwopeopL -= comTwopeopKoL #扣血量(惨败)
elif comTwoStateE == 2 or comTwoStateE == 3:
comTwopeopKoL = random.randint(0,comTwospawTegeS)
comTwospawKoL = random.randint(0,comTwopeopS)
print("你们各有所伤,毒蛇扣了" + str(comTwospawKoL) + "血量,你扣了" + str(comTwopeopKoL) + "血量")
comTwopeopL -= comTwopeopKoL #扣血量(各有损伤)
comTwospawTegeL -= comTwospawKoL #扣毒蛇血量
elif comTwoStateE == 4:
#直接打死
print("你牛啊,直接打死了一条毒蛇!")
comTwospawlen.pop() #移除一条毒蛇
if len(comTwospawlen) == 2: #重新计算
comTwospawTegeS = (comTwospawL1 + comTwospawL2) / 2
if len(comTwospawlen) == 1:
comTwospawTegeS = comTwospawL1 / 1
elif camTwoState == 1:
#玩家进攻
print("你向毒蛇发起了进攻!")
#问动作
ansComTwopeopExer = int(input("动作(1:跳起来打;2:直接冲过去):"))
if ansComTwopeopExer == 1:
#跳起来打
comTwoState = random.randint(0,2) #随机状态
if comTwoState == 0:
comTwospawKoL = random.randint(1,comTwopeopS) #扣血量
comTwospawTegeL -= comTwospawKoL
print("你打中了了一条毒蛇,毒蛇扣了" + str(comTwospawKoL) + "血量!")
elif comTwoState == 1:
print("你打了一拳,可是没有打到!让它跑了...") #没打着
elif comTwoState == 2:
#不仅没打着,还扣了血量
comTwopeopKoL = random.randint(0,comTwospawTegeS)
print("你打了一拳,可是没有打到!还被它咬了一口,你被扣了" + str(comTwopeopKoL) + "血量")
comTwopeopL -= comTwopeopKoL
elif ansComTwopeopExer == 2:
#直接冲过去
comTwoState = random.randint(0,2) #再次随机状态
if comTwoState == 0:
comTwospawKoL = random.randint(1,comTwopeopS)
comTwospawTegeL -= comTwospawKoL
print("你打中了了一条毒蛇,毒蛇扣了" + str(comTwospawKoL) + "血量!")
elif comTwoState == 1:
comTwopeopKoL = random.randint(0,comTwospawTegeS)
print("你打了一拳,可是没有打到!还被它咬了一口,你被扣了" + str(comTwopeopKoL) + "血量")
comTwopeopL -= comTwopeopKoL
elif comTwoState == 2:
print("你居然直接打死了一条毒蛇!")
comTwospawlen.pop()
if len(comTwospawlen) == 2:
comTwospawTegeS = (comTwospawL1 + comTwospawL2) / 2
if len(comTwospawlen) == 1:
comTwospawTegeS = comTwospawL1 / 1
camTwoT += 1 #加次数
t.sleep(1)
#继续随机状态
camOneState = random.randint(0,1)
print("等待更新")