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."呃,嗨。我需要帮助。正如你所看到的,这是一个非常基本的文字游戏,让玩家与环境互动。我计划扩展到互动的事情,与此我不需要帮助。但有了游戏圈我就知道了。您可能会意识到,但对于那些没有意识到的人,每次我编写命令时,程序都会关闭。有人告诉我,我需要一个游戏循环来完成这个任务,但我不知道怎么做。
我要告诉你的是,和你相比,我有点弱智。我不是编程天才,我只是喜欢编程。所以请告诉我怎么做,而不是为什么。我会自己想办法的,因为我有世界上所有的时间。如果我需要知道为什么,我会再问你一次!
发布于 2015-10-15 10:08:01
你必须用一个循环就像时间一样。你必须从循环内部得到输入。你必须检查游戏是否结束。由于raw_input()函数,输入将自动重置:
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."
haveKey = False
applesExist = True
gameover = False
while gameover == False:
input = raw_input("> ")
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."
gameover = True
elif input == "drink tea":
print "You put some tea in your mouth, but immediately spit it out."https://stackoverflow.com/questions/33145209
复制相似问题