print "Welcome to the game. In the game you can 'look around' and 'examine things'."
print "There is also some hidden actions."
print "You wake up."
input = raw_input("> ")
haveKey = False
applesExist = True
if input == "look around":
print "You are in a dusty cell. There is a barrel in the corner of the room, an unmade bed,"
print "a cabinet and chest. There is also a cell door."
elif haveKey == False and input == "open door":
print "The door is locked."
elif haveKey == True and input == "open door":
print "You open the door, walk out and immediately gets shot with an arrow. You won, kinda."
elif input == "examine barrel":
print "There is apples in the barrel."
elif applesExist == True and input == "eat apple":
print "Mmmmh, that was yummy! But now there are no apples left..."
applesExist = False
elif applesExist == False and input == "eat apple":
print "sury, u et al aples befur!!1111"
elif input == "examine bed":
print "The bed is unmade, and has very dusty sheets. This place really needs a maid."
elif input == "sleep on bed":
print "You lie down and try to sleep, but you can't because of all the bugs crawling on you."
elif input == "examine chest":
print "There is a key in the chest."
elif input == "take key":
haveKey = True
print "You take the key."
elif input == "examine cabinet":
print "The cabinet is made of dark oak wood. There is a endless cup of tea in it."
elif input == "drink tea":
print "You put some tea in your mouth, but immediately spit it out."
print "It seems it has been here for quite some time."
else:
print "Huh, what did you say? Didn't catch that."
嗯,嗨。我需要帮助。正如你可以看到这是一个非常基础的文本游戏, 让玩家与环境进行交互。我打算扩大 互动的事情,我不需要任何帮助。但随着游戏循环,我做到了。您可能会意识到,但对于那些不这样做的人,每次我写一个命令时,程序都会关闭。我被告知我需要一个游戏循环来做到这一点,但我不知道如何。文字游戏 - 游戏循环
我需要告诉你的是,与你相比,我有点迟钝。我不是编程天才,我只是简单地享受编程。所以,请说,如何,而不是为什么。我会自己解决这个问题,因为我一直都在这个世界上。如果我需要知道为什么,那么我会再问你一次! = D
您*了解循环以及如何制作一个?例如,让一个循环迭代*而某些条件为真? –
是的,kinda = D。我知道如何让东西永远循环,或者直到布尔变化,但这是我的限制=) – Elsvaer
然后想一会儿(双关语不打算):你做一个循环,而用户不想退出,就这么简单。您需要一个初始化为“True”的变量,并保持为“True”,直到用户输入一个要退出的命令,并将该变量用作循环条件。 –