麻烦在我的基本Python文本冒险中去不同的房间

时间:2015-05-13 23:28:18

标签: python

我正在编程课程的介绍中并且一直在尝试创建一个简单的文本冒险,但每次我(尝试)去另一个房间我都会得到一个名称错误,说明特定的房间没有被定义。我最初认为这是因为我在结尾处的else语句后再次调用了房间,并且再次在它下面调用了房间,但这并没有改变任何东西。

#This is a random text adventure game. Enjoy!

def main():
    print("You wake up in a cave without a clue of how you got there. Your head is throbbing. \nInsistent on figuring out what happened to you, you decide to explore the cave in search of answers. \n")
    print("You can do the following things: \n"
        "'go left' - Explore the tunnel on your left. \n"
        "'go right' - Explore the tunnel on your right. \n")
#Evaluates the player's choice.
    choice = input("What do you do?: ")
    if choice == 'go left':
        print("You stumble your way down the left tunnel.\n")
        left_cave()
    if choice == 'go right':
        print("You stumble your way down the right tunnel.\n")
        right_cave()
    else:
        print("That's not a direction.. Maybe your head is hurting because you don't know what left and right means. :D\n")
main()

#Defines the left cave.
def left_cave():
    print("After a short walk you find yourself in smaller room then the room you woke up in. \n There is some writing on the walls.")
    print("You can do the following things: \n"
        "'examine' - Examine the writing on the wall. \n"
        "'look around' - Take a look around the room. \n"
        "'go back' - Go back to the main room. \n")
    choice = input("What will you do?: ")
    if choice == 'examine':
        print("I see you have made it this far.  If you want to know what really happened to you then you will have to make it to the end of the cave.")
        middle_room()
    if choice == 'look around':
        print("You see just another darkly lit room.  This room smells.  You notice the writing on the wall again.")
        left_cave()
    if choice == 'go back':
        print("You make your way back to the room you woke up in.")
        main()
    else:
        print("There is nothing in this room that matches that.. C'mon.")
left_cave()

0 个答案:

没有答案