[Tutor] A Text Adventure Problem

John Bochicchio luckytsukune at gmail.com
Sun Mar 24 20:41:43 CET 2013


I've been trying to write a simple test text adventure, but have been
running into serious problems. Here is the error I get when I run it. It
will give me the opening text and lets me make my first choice. Then I get
this.

error "Traceback: (Most recent call last)
file "game1.py", line 104, in <module>
RUNNER (ROOMS, shack_front)
file "game1.py", line 100 in runner
room = map[next]
keyerror= none

And here is my code.

from sys import exit

from random import randint



def death():

    quips = ["You've become a zombie and eat you pals. Douche."

             "You've died and left your comrades to fend for themselves.
Douche"

             "Your whole group dies because of you. Douche."

             "You've got terrible planning skills, and ruined the teams
chances of survival. Douche."]



    print quips[randint(0, len(quips)-1)]

    exit(1)





def shack_front():

    print "The year is 2062, and the zombies have risen. You're not a
doctor, and you have no training. You're just a guy trying to survive."

    print "......" * 8

    print "You stand in front of a broken down shack, you here gurgles and
screams from inside. There is a window to the side of the house that you
can see through, or a door you can burst into."

    print "......" * 8

    print "Window or door?"



    action = raw_input(">")



    if action == "window":

        print "You silently walk over to the dirty window. You look inside
to see a man held captive by 2 marauders. The marauders are armed with
bats, and don't seem to know what they're doing. You have 1 9mm glock with
12 bullets."



    elif action == "door":

         print "You burst through the door with your shoulder. You see only
one marauder. You shoot him in the chest and notice a man tied up in a
chair. You walk over to him but feel a sharp pain in the back of your head.
You never saw the second marauder coming."

         return 'death'



    else:

        print "Not a valid command"

        return 'shack_front'



def shack_window():

    print "Do you burst through the door or try to fire through the window
at the marauders?"



    action = raw_input(">")



    if action == "window":

        print "You fire off three shots through the window. Two in the
chest of the first marauder, one in the neck of the other. They fall to the
ground, dead. You walk inside to see if the man is okay."



    elif action == "door":

        print "You burst through the door and fire two shots into the first
marauder. You remember seeing two, so you turn around and put one bullet
through the head of the one behind you. You walk over to the man to see if
he's okay."



    else:

        print "Not a valid command"

        return 'shack_window'



def shack_interior():

    print "You ask the man if he is okay."

    print "He says that he will be fine, and that his name is Carmicheal."

    print "He says he is an ex marine, but was ambushed by five of them. He
believes that three went out on a scavenging party."

    print "Carmicheal believes that if you wait for them to come back and
ambush them, you will be able to get food, ammo, and perhaps even a gun."

    print "Do you tell him yes, or no?"



    action = raw_input(">")



    if action == "yes":

        print "You tell Carmicheal yes. You both hide in the back of the
shack. Carmicheal takes a cleaver and you pull out your glock. 30 minutes
pass."

        print "......" * 10



    elif action == "no":

        print "Carmicheal looks at you puzzled. You ask if he wants to come
with you, but he only gets mad. He screams at you for not following the
plan, but you walk out."

        print "You hear a rush of sound as the cleaver hits the back of
your skull. You are dead."

        return 'death'



    else:

        print "Not a valid command"

        return 'shack_interior'



def shack_back():

    print "You hear the sound of boots in the next room. Carmicheal and you
stand up, ready to attack. Do you go in first, or him?"



    action = raw_input(">")



    if action == "him":

        print "Carmicheal goes in first. His cleaver tearing through the
neck of the first marauder. You see one trying to pull the gun from his
waist. You fire two shots into the marauder, killing him. The third
marauder grabs you from behind. You elbow him in the abdomen, leaving
Carmicheal just enough room to throw his cleaver into the marauder's head."

        print "You have both survived. Do you scavenge the dead bodies?"



    elif action == "me":

         print "You go in first. You see the three marauders lined up like
bowling pins. You let off six shots. Killing first the marauder with the
gun, then the two with knives and bats. You easily killed these men without
even breaking a sweat. Their bodies lay before you. Do you want to scavenge
them?"



    else:

        print "Not a valid command."

        return 'shack_back'



ROOMS = {

    'death': death,

    'shack_front': shack_front,

    'shack_window': shack_window,

    'shack_interior': shack_interior,

    'shack_back' : shack_back

}





def runner(map, start):

    next = start



    while True:

        room = map[next]

        print "\n--------"

        next = room()



runner (ROOMS, 'shack_front')


-- 
A computer without a Microsoft operating system is like a dog without
bricks tied to its head.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130324/e9e3823b/attachment.html>


More information about the Tutor mailing list