因此,我对Python还比较陌生,如果这个问题看起来很蠢,我会提前道歉。
在练习游戏中,我试图弄明白如何使我自己的文字为基础的冒险,玩家被问到他们是否会继续,他们必须使用他们的灯笼进一步进入隧道,随后这样说;
elif nolamp and lan2 == ("use lantern") or lan2 == ("USE LANTERN") or lan2 == ("Use lantern") or lan2 == ("use LANTERN") or lan2 == ("Use LANTERN"):
litlamp = True
nolamp = False
tunnel2 = True
print ("")
print ("You light the lantern and can now see.")
print ("The tunnel is still very dark ahead.")
time.sleep(2)
print ("The walls look wet.")
time.sleep(1.6)
print ("Will you go back?")
print ("")如果他们的灯笼不亮,它就会用它打印出来;
elif nolamp and lan2 == ("n") or lan2 == ("N") or lan2 == ("no") or lan2 == ("NO") or lan2 == ("No"):
print ("You would continue, but it's too dark and cold.")
print ("To go any farther like this would be a bad idea.")
time.sleep(2.5)
print ("Will you go back?")上述语句是在单独的while循环中定义的;
lanternv2 = True
tunnelv1 = True
nolamp = False
tunnel2 = False
litlamp = False当他们的灯笼被点燃时,玩家应该继续;
elif tunnel2 and lan2 == ("n") or lan2 == ("N") or lan2 == ("no") or lan2 == ("NO") or lan2 == ("No"):
tunnel3 = True
tunnel2 = False
print ("You continue onward.")
print ("You still see no light and the entrance is disappearing behind you.")
time.sleep(2.5)
print ("It's very very cold.")
time.sleep(1.1)
print ("Will you go back?")然而,我的问题是,当玩家试图使用"n“以外的任何其他答案时,当他们的灯笼被点燃时,将会被打印的就好像他们的灯没有被使用过一样。
有人知道为什么会这样吗?我需要更具体一点吗?谢谢,如果这是个愚蠢的问题,很抱歉。
发布于 2022-04-15 22:34:29
我无法从代码中遵循您想要的内容,但希望下面给您提供一些需要遵循的想法。具体来说,当他们的灯笼被点燃时,你会问"n“以外的任何其他答案,但它会打印出来,就像他们的灯没有被使用过一样。唯一的答案不是“否”是“使用灯笼选项”,但该选项检查球员是否没有灯。其他声明只有在你回答“否”时才会打印出来。因此,在我看来,代码中打印的部分不包括在问题中。
我试着让它简单地跟随,也许它可以提供一些线索!不管怎么说,我写得很开心。
import random
# I tried to keep the code similar to yours
lanternv2 = True
tunnelv1 = True
nolamp = False
tunnel2 = False
litlamp = False
lan2 = ""
#The statements are defined above within a separate while loop;
while lan2 != "no" and lan2 != "n" and lan2 != "y":
lan2 = input("Do you want to use a lantern to enter the dark and very spooky cave?")
lan2 = lan2.lower()
if lan2 == "y":
# Player has entered the cave
litlamp = True
nolamp = False
tunnel2 = True
inCave = True #always true while in the cave
print ("")
print ("You light the lantern and can now see.")
print ("The tunnel is still very dark ahead.")
#time.sleep(2)
print ("The walls look wet.")
#time.sleep(1.6)
while(inCave):
# generates a random number 0 - 1
if(random.random() <.1):
print("Your lantern sputters and the light disappears")
litlamp = False
caveInput = input("Will you go back?").lower()
if not litlamp and (caveInput == ("n") or caveInput == ("no")):
print ("You would continue, but it's too dark and cold.")
print ("To go any farther like this would be a bad idea.")
#time.sleep(2.5)
print ()
#The player should continue when their lantern is lit with this;
elif litlamp and (caveInput == ("n") or caveInput == ("no")):
# They can only continue into the cave
print ("You continue onward.")
print ("You still see no light and the entrance is disappearing behind you.")
#time.sleep(2.5)
print ("It's very very cold.")
#time.sleep(1.1)
else: # should check if yes but this is taking too long lol
print("you flee the cave, never to return")
#break out of the while loop
inCave = false
print("You have fled the cave")https://stackoverflow.com/questions/71888350
复制相似问题