我正在编写某种基于文本的游戏,因为我需要做点什么。
我的代码在这里
#dis is a game
cmd = "undefined"
candle = False
notebook = False
explored = False
pick = "undefined"
use = "undefined"
name = "undefined"
import time
print "You wake up in a barely lit room."
time.sleep(2)
while candle == False and name != "undefined":
cmd = raw_input("?").lower()
time.sleep(2)
if cmd == "explore":
print "The room is lit by a candle."
time.sleep(2)
print "There is a notebook laying on the ground."
explored = True
time.sleep(2)
elif cmd == "pick up":
pick = raw_input("pick up what: ").lower()
time.sleep(2)
if pick == "candle":
candle = True
print "You picked up the candle."
time.sleep(2)
print "You decide to hold it in front of you."
elif pick == "notebook" and explored == True:
notebook = True
print "You picked up the notebook."
time.sleep(2)
elif pick == "help" and explored == False:
print "candle"
elif pick == "help" and explored == True:
print "candle"
print "notebook"
elif cmd == "use":
use = raw_input("use what: ").lower()
if use == "candle" and candle == True:
print "you're already holding out your candle in front of you."
time.sleep(2)
elif use == "notebook" and notebook == True:
print "you open the notebook on the first page."
time.sleep(2)
print "'Hello stranger, can I have your name please?'"
time.sleep(2)
name = raw_input("?")
time.sleep(2)
if name.lower() == "no":
print "words appear when you're done writing."
time.sleep(2)
print "well... I think you don't have any reason to be here then."
time.sleep(60*60)
else:
print "thank you."
time.sleep(2)
if candle == True:
print "I think you're ready to go to the next room."
else:
print "Maybe you should pick up that candle."
elif cmd == "help":
print "explore - get more information of your surroundings."
print "pick up - pick up something in your surroundings."
print "use - use an item in your inventory."
cmd = "undefined"
pick = "undefined"
use = "undefined
#first room complete
print "A bright light surrounds you."
以某种方式显示唤醒消息,2秒后显示房间已清除消息。 请有人帮帮我吗?
我把它改成了 而不是蜡烛, 它现在有效
答案 0 :(得分:1)
因为你的while语句以false开头。您将蜡烛设置为False并将其命名为" undefined",因此条件本身为false,并且从不输入代码。也许您打算检查名称是相等到" undefined"?