954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How would I make a text adventure?

Just wondering how the game would be put together, maybe even a step by step tutorial. I could use this to practice with the commands used without Tkinter or Pygame. This could be a good learning experience.

chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

The easiest game would be with a number of rooms. Draw yourself a map of 9 rooms (maybe a 3x3 pattern). Make notes on the map about details of the room, number of doors, contents, pictures, furniture and so on.

Let's say you come into the first room from the south. Now this room has a total of 4 doors, one to the south (S) where you came in, one to the east (E), north (N) and west (W). Ask the player which door he/she wants to enter. Like: "You want to go E, N or W?"

Rooms may have 2, 3 or 4 doors. Now the adventure begins. Some rooms contain a strength potion, or weapon, or some treasure, or cryptic instructions to read, or monsters to fight. When you fight a monster you lose strength. Some monsters are stronger than others. The player starts with a certain amount of strength points and gains more strength by picking up strength potions. Also loses less strength by picking up a better weapons. Each weapon has hit points, the more the better!

Describe the new room as the player enters. Like: "You entered a room that is painted green. There is a picture on the wall of an elderly gentleman. There are 5 gold pieces on the table for you. There are doors to the E and W. Do you want to go E or W?"

The rest is up to your imagination. When the player finds enough treasure (say 50 gold pieces total), he/she will have to get back to the exit alive to win the game. The room descriptions will aid. To make things more difficult, add a basement (stairs/doors to go down or D) or an upstairs (U) floor.

Show the player's present strength, weapon, gold pieces collected, and so on somehere on the screen.

Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
 

I meant, should I def a room class, and make room objects with specific instructions?

chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Could someone please help me by telling me what code structure I should use, and an example? I'm trying, but I have no idea how to make it work. I've tried making a Room class, and making each room a sub-class am I on the right track? I just need pointing in the right direction.

chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

It depends what you want to do. If you just want to make a simple fun game, there is no need for class objects. If you want to to do this to learn OOP, then by all means go for it. Your progress will be initially slow, because there is quite a learning curve.

Your approach making a class Room with the basics that all rooms can share, and then a class for each individual room that inherits the class Room makes the most sense. However, a lot of thought has to be put into this approach before any of the fun starts.

Just let us know what you have come up with, and how you would test each class to make sure it does what you want it to do.

Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
 

Text based role playing games (RPG) used to be plentiful in the early days of personal computing. Usually written in Basic, C or Pascal, but I have not seen just a text based RPG in a modern language like Python.

I would most likely define a function for each room and handle all the descriptions, actions, and connections to other rooms from there. Looks like an interesting project and a good way to learn Python skills! Later, as the project grows, you can use classes to group the functions together.

You could start with a 3 by 3 cluster of connected rooms and ask the player to explore all the rooms with the least amount of moves. Hide a few gold pieces and maybe add a secret door or two that can be opend by solving a riddle. As you get the hang of it, you can add weapons, monsters, spells and potions.

There are some GUI based RPGs on the PyGame website, but that gets to be pretty large and complex for beginners.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Doing one command at a time, teting each one. Need help, I tried defining gold as a global variable, as it wasn't working when I just created it out of the loop, but the Reading Room won't add 30 gold Where am I going wrong?

#Text Adventure.py
#By Chris O'Leary

global gold
gold=0

def start():
    print '''You find yourself in the foyer of a large house. You
    have no idea how you got there. You look around, and see the front door.
    It is locked and barred, and the bar is nailed down. There is
    no way to open it. There are three other doors in the area. A voice says '50 gold is what you need,
    to escape my grasp, of this take heed!'''
    print
    
def foyer():
    print "Current Gold = ",gold
    print '''You are in the Foyer. The walls are lined with trophy cabinets
    and suits of armour. The exits are (N)orth, (E)ast and (W)est.
    Type 'Help' for a full list of commands.'''
    print
    prompt_foy()
    
def prompt_foy():
    prompt_f = raw_input("Type a command: ")
    if prompt_f == "W":
        reading_room()
    elif prompt_f == "Help":
        print "Look, Examine (Object), N, W, E, S, Take (Item)"
        prompt_foy()
    elif prompt_f == "Examine Armour":
        print "The armour is rusted, and not of any use."
        prompt_foy()
    elif prompt_f == "Examine Cabinet":
        print '''The cabinet is lined with trophies, dating back to the 1800s.
        Seems this was a talented family.'''
        prompt_foy()
    elif prompt_f == "S":
        if gold < 50:
            print "You can't get out untill you have 50 gold."
            prompt_foy()

def reading_room():
    print "Current Gold = ",gold
    print '''You are in an large reading room. The room is stuffed with novels
    and poetry books on every shelf. There is a large table in the middle
    of the room. It has a reading lamp, and a cluster of books scattered about
    on top. The exits are (N)orth and (E)ast. Type 'Help' for a full list of
    commands.'''
    print
    prompt_rea()
    
def prompt_rea():
    prompt_r = raw_input("Type a command: ")
    if prompt_r == "E":
        foyer()
    elif prompt_r == "Help":
        print "Look, Examine (Object), N, W, E, S, Take (Item)"
        prompt_rea()
    elif prompt_r == "Look":
        "You see 30 gold pieces on the table."
        prompt_rea()
    elif prompt_r == "Take Gold":
        print "You get 30 gold!"
        gold = gold+30
        reading_room()
start()
foyer()


Can you see the problem?

chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 
def prompt_rea():
    global gold
    ....
    ....

Can you see the problem?

if you want to use gold as global, u might like to put "global gold" inside prompt_rea()

ghostdog74
Junior Poster
156 posts since Apr 2006
Reputation Points: 75
Solved Threads: 44
 

Thanks, it works now!

chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

You are off to an interesting start! Nice foyer, hehe, almost like mine at home!

Declare the variable gold global in each function that uses this global variable. This would also apply to strength, weapons, or any monster-kill flags. If a monster has been killed in a room you can set the flag so that this monster does not attack again. Of course you could revive the monster and make things much more difficult.

Sorry, I just realized that in your first version you might not go with monsters yet. Just explore, find enough gold, and get out! It will be interesting to read all your room descriptions.

Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
 

I'm using flags to prevent getting the same gold hoardes twice. Setting the variable to false when the gold is taken. Done three rooms:

Reading Room -- Foyer -- Servants Quarters

That's a small map -----------^

Just sticking with the goal of 50 gold for now.



So Ene_Uran, your imprisoned in your own home too? You got the 50$ toll to get out :P.

chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

6 rooms done! Just need to do the top three, the try...except statements and the ending!

chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

I hope you let us see the result. We can play it, and give you helpful hints, if you don't mind!

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

I just have 2 rooms to go, and an ending. Then I'll playtest it, using every command programmed making sure they all work. You can wait a couple more days right?

chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

I am willing to wait! Good things take their time. Hehe, try to tell that to your boss!

Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
 
I am willing to wait! Good things take their time. Hehe, try to tell that to your boss!



Well, wait no longer! Advent House v1.0 is here. Let me know of any formatting errors. Hope you like it.

Attachments TextAd.zip (4.33KB)
chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Nice, nice, nice and spooky!!!! Just in time for Halloween!
I haven't tested it all the way, but made few recommendations and corrections indicated by the #!!!!! marks:

#Text Adventure.py
#By Chris O'Leary

# functions will pick the external gold value (for instance), as long as gold is not 
# a variable declared locally inside the function, this behaviour may change in future
# versions of Python, the safest way would be add the statement "global gold" to each 
# function that uses it !!!!!!!!!!!!

"""
# global declarations go into the functions that use them!!!!!
global gold
global gotGold_reading
global gotGold_SQ
global gotGold_liv
global gotGold_draw
global gotGold_din
"""

gold = 0
gotGold_reading = 0
gotGold_SQ = 0
gotGold_liv = 0
gotGold_draw = 0
gotGold_din = 0

# recommend to make help a function and give a few more details ...
def help():
    print "look, examine (object), n, w, e, s, take (item)"
    print "Example: examine vase, take gold"

    

def start():
    print '''
        ADVENT HOUSE v1.0
    You find yourself in the foyer of a large house. You
    have no idea how you got there. You look around, and see the front door.
    It is locked and barred, and the bar is nailed down. There is
    no way to open it. There are three other doors in the area. A voice says
    '50 gold is what you need,
    to escape my grasp, of this take heed!'

    Note: All instructions must be typed in small letters. No capitals.'''
    # recommend to add .lower() to all raw_input() so you don't need the above note!!!!!
    # add this Note: All commands can be entered in lower or upper case!
    print
    
def foyer():
    global gold  # !!!!!!!!
    print "     Current Gold = ",gold
    print '''    You are in the Foyer. The walls are lined with trophy cabinets
    and suits of armour. The exits are (N)orth, (E)ast and (W)est.
    Type 'help' for a full list of commands.'''
    print
    prompt_foy()

def foy_desc():
    print '''    The walls are lined with trophy cabinets and suits of armour.
    The exits are (N)orth, (E)ast and (W)est.'''
    print
    prompt_foy()
    
def prompt_foy():
    global gold  # !!!!!!!
    # make input string lower case automatically!!!!
    prompt_f = raw_input("Type a command: ").lower()
    try:
        if prompt_f == "w":
            reading_room()
        elif prompt_f == "e":
            servants_quarters()
        elif prompt_f == "help":
            # made help a function call here ...
            help()
            #print "look, examine (object), n, w, e, s, take (item)"
            print
            prompt_foy()
        elif prompt_f == "examine armour":
            print "The armour is rusted, and not of any use."
            print
            prompt_foy()
        elif prompt_f == "examine cabinet":
            print '''    The cabinet is lined with trophies, dating back to the 1800s.
            Seems this was a talented family.'''
            print
            prompt_foy()
        elif prompt_f == "look":
            foy_desc()
        elif prompt_f == "s":
            if gold < 50:
                print "You can't get out untill you have 50 gold."
                print
                prompt_foy()
            elif gold == 50:
                ending()
        elif prompt_f == "n":
            main_hall()
        else:
            print "That command is invalid"
            print
            prompt_foy()
    except ValueError:
        print "That command is invalid"
        print
        prompt_foy()

def reading_room():
    global gold   # !!!!!
    print "      Current Gold = ",gold
    print '''    You are in an large reading room. The room is stuffed with novels
    and poetry books on every shelf. There is a large table in the middle
    of the room. It has a reading lamp, and a cluster of books scattered about
    on top. The exits are (n)orth and (e)ast. Type 'help' for a full list of
    commands.'''
    print
    prompt_rea()

def rea_desc():
    print '''    The room is stuffed with novels and poetry books on
    every shelf. There is a large table in the middle of the room.
    It has a reading lamp, and a cluster of books scattered about
    on top. The exits are (n)orth and (e)ast.'''
    print
    prompt_rea()
    
def prompt_rea():
    global gold
    global gotGold_reading
    prompt_r = raw_input("Type a command: ").lower()  #!!!!!
    try:
        if prompt_r == "e":
            foyer()
        elif prompt_r == "n":
            drawing_room()
        elif prompt_r == "help":
            print "look, examine (object), n, w, e, s, take (item)"
            print
            prompt_rea()
        elif prompt_r == "examine table":
            if gotGold_reading == 0:
                print "You see 30 gold pieces on the table."
                print
                prompt_rea()
            elif gotGold_reading == 1:
                print "The table is cluttered with books."
                print
                prompt_rea()
        elif prompt_r == "look":
            rea_desc()
        elif prompt_r == "take gold":
            if gotGold_reading==0:
                print "You get 30 gold!"
                print
                gold=gold+30
                gotGold_reading=1
                reading_room()
            elif gotGold_reading==1:
                print "No gold in here"
                print
                prompt_rea()
        elif prompt_r == "examine shelves":
            print '''    There are numerous bookshelves and countless books,
            and some novels are scattered under the reading lamp. Obviously
            they were terrible housekeepers.'''
            print
            prompt_rea()
        else:
            print "That command is invalid"
            print
            prompt_rea()
    except ValueError:
        print "That command is invalid"
        print
        prompt_rea()
def servants_quarters():
    global gold  # !!!!!
    print "Current Gold = ",gold
    print '''    You are in a small room, with a large, old bed. There is an open
    wardrobe in the corner with a small amount of clothes still in it.
    Obviously a servant used to sleep here.

    Type 'help' for a full list of commands.'''
    print
    prompt_SQ()
def serv_desc():
    print '''    There is an open wardrobe in the corner with
    a small amount of clothes still in it. There is a large bed.'''
    print
def prompt_SQ():
    global gold
    global gotGold_SQ
    prompt_s = raw_input("Type a command: ").lower()  #!!!!!
    try:
        if prompt_s == "w":
            foyer()
        elif prompt_s == "n":
            living_room()
        elif prompt_s == "help":
            print "look, examine (object), n, w, e, s, take (item)"
            print
            prompt_SQ()
        elif prompt_s == "examine bed":
            if gotGold_SQ == 0:
                print '''    There are no bedclothes. The mattress is old and motheaten. You
                see a hole with gold pieces in it. There are five.'''
                print
                prompt_SQ()
            elif gotGold_SQ == 1:
                print '''    There are no bedclothes. The mattress is old and motheaten. There
                is a hole in the matress.'''
                print
                prompt_SQ()
        elif prompt_s == "examine wardrobe":
            print "The door is ajar. You see a maid's uniform, but there is nothing of interest."
            print
            prompt_SQ()
        elif prompt_s == "take gold":
            if gotGold_SQ == 0:
                print "You get 5 gold!"
                print
                gold = gold+5
                gotGold_SQ = 1
                servants_quarters()
            elif gotGold_SQ == 1:
                print "There is no gold here."
                print
                prompt_SQ()
        elif prompt_s == "look":
            serv_desc()
        else:
            print "That command is invalid"
            print
            prompt_SQ()
    except ValueError:
        print "That command is invalid"
        print
        prompt_SQ()
def living_room():
    global gold         # !!!!!
    print "Current Gold = ",gold
    print '''    You are in a large room. There is an old, decaying sofa and
    a chair that has fallen into disrepair. Both are covered in cobwebs.
    There is an old, dusty fireplace, with a large chimney. The logs and carpet
    are caked with soot, presumably recent. It appears to have been a living
    room at some point. There are exits (n)orth, (w)est and (s)outh.

     Type 'help' for a full list of instructions.'''
    print
    prompt_liv()
def liv_desc():
    print '''    There is an old, decaying sofa and a chair that has
    fallen into disrepair. Both are covered in cobwebs. There is an old,
    dusty fireplace, with a large chimney. The logs and carpet are caked
    with soot, presumably recent.'''
    print
    prompt_liv()
    
def prompt_liv():
    global gold
    global gotGold_liv
    print
    prompt_l = raw_input("Type a command: ").lower()  #!!!!!!
    try:
        if prompt_l == "s":
            servants_quarters()
        elif prompt_l =="n":
            conservatory()
        elif prompt_l == "examine sofa":
            print '''    The sofa is in disrepair, there are springs poking
            out everywhere.'''
            print
            prompt_liv()
        elif prompt_l == "help":
            print "look, examine (object), n, w, e, s, take (item)"
            print
        elif prompt_l == "w":
            main_hall()  # was mail_hall()  !!!!!!!!!!
        elif prompt_l == "examine fireplace":
            if gotGold_liv == 0:
                print "There are ten, slightly sooty, gold pieces in the hearth."
                print
                prompt_liv()
            elif gotGold_liv == 1:
                print "The hearth is a mess."
                print
                prompt_liv()
        elif prompt_l == "examine chair":
            print "The chair is in awful condition. The cushions have rising damp."
            print
            prompt_liv()
        elif prompt_l == "take gold":
            if gotGold_liv == 0:
                print "You got 10 gold!"
                print
                gold = gold+10
                gotGold_liv = 1
                living_room()
            elif gotGold_liv == 1:
                print "There is no gold here."
                print
                prompt_liv()
        elif prompt_l == "look":
            liv_desc()
        else:
            print "That command is invalid"
            print
            prompt_liv()
    except ValueError:
        print "That command is invalid"
        print
        prompt_liv()

def main_hall():
    global gold  # !!!!!
    print "Current Gold = ",gold
    print '''    You are in the main hall. You see a staircase, however it has
    collapsed. There are three portraits surrounding you, captioned with names:
    Master Daniel Redwood, Mistress Stephanie Redwood and Mister Ivan Redwood.
    There are four exits, (n)orth, (s)outh, (e)ast and (w)est.'''
    print
    prompt_main()
def main_desc():
    print '''    You see a staircase, however it has
    collapsed. There are three portraits surrounding you, captioned with names:
    Master Daniel Redwood, Mistress Stephanie Redwood and Mister Ivan Redwood.'''
    print
    prompt_main()
def prompt_main():
    prompt_m = raw_input("Type a command: ").lower()  #!!!!!!
    try:
        if prompt_m == "s":
            foyer()
        elif prompt_m == "e":
            living_room()
        elif prompt_m == "w":
            drawing_room()
        elif prompt_m == "n":
            kitchen()
        elif prompt_m == "help":
            print "look, examine (object), n, w, e, s, take (item)"
            print
            prompt_main()
        elif prompt_m == "look":
            main_desc()
        elif prompt_m == "examine pictures":
            print '''    The family look happy in their respective photos.
            They are wearing champion ribbons.'''
            prompt_main()
        elif prompt_m == "examine staircase":
            print "The stairs are totally destroyed."
            prompt_main()
        else:
            print "That command is invalid"
            print
            prompt_main()
    except ValueError:
        print "That command is invalid"
        print
        prompt_main()
def drawing_room():
    print "Current gold = ",gold
    print '''    You are in the drawing room. There is a table with documents
    scattered all over it. There is a single painting, a portrait of the wife,
    on the south wall. The bookshelves here are filled with diaries.

    The exits are (n)orth, (s)outh and (e)ast.'''
    print
    prompt_draw()
def draw_desc():
    print '''    There is a table with documents scattered all over it.
    There is a single painting, a portrait of the wife, on the south wall.
    The bookshelves here are filled with diaries.'''
    print
    prompt_draw()
def prompt_draw():
    global gold
    global gotGold_draw
    prompt_d = raw_input("Type a command: ").lower()  #!!!!
    try:
        if prompt_d == "s":
            reading_room()
        elif prompt_d == "e":
            main_hall()
        elif prompt_d =="n":
            dining_room()
        elif prompt_d == "look":
            draw_desc()
        elif prompt_d == "examine bookshelves":
            print "The shelves are cluttered with diaries."
            print
            prompt_draw()
        elif prompt_d == "examine table":
            print '''    The floor plans are detailed here. The ground floor is layed out
            in a three-by-three grid.'''
            print
            prompt_draw()
        elif prompt_d == "examine portrait":
            if gotGold_draw == 0:
                print '''    She was hauntingly beautiful. There is a single
                gold piece adorning the frame.'''
                print
                prompt_draw()
            elif gotGold_draw == 1:
                print "She was hauntingly beautiful."
                print
                prompt_draw()
        elif prompt_d == "take gold":
            if gotGold_draw == 0:
                print "You got 1 gold!"
                gold = gold+1
                gotGold_draw = 1
                prompt_draw()
        elif prompt_d == "help":
            print "look, examine (object), n, w, e, s, take (item)"
            print
            prompt_draw()
        else:
            print "That command is invalid"
            print
            prompt_draw()
    except ValueError:
            print "That command is invalid"
            print
            prompt_draw()
def conservatory():
    global gold  #!!!!
    print "Current gold = ",gold
    print '''    You are in a large glass conservatory. There are plants everywhere.
    There is a set of garden furniture right in the centre, and an assortment of
    plants, potted around the edge. There are exits to the (s)outh and (w)est.

    Type 'help' for a full list of commands.'''
    print
    prompt_con()
def con_desc():
    print '''    You are in a large glass conservatory. There are plants everywhere.
    There is a set of garden furniture right in the centre, and an assortment of
    plants, potted around the edge.'''
    print
    prompt_con()  #!!!!!!!
def prompt_con():
    prompt_c = raw_input("Type a command: ").lower()  #!!!!!!
    try:
        if prompt_c == "s":
            living_room()
        elif prompt_c == "w":
            kitchen()
        elif prompt_c == "examine plants":
            print '''    There are several varieties of flowers and vines planted
            in various locations in the conservatory.'''
            print
            prompt_con()
        elif prompt_c == "look":
            con_desc()
        elif prompt_c == "examine furniture":
            print '''    The furniture is a complete set. It is white. There are
            three tables and a chair.'''
            print
            prompt_con()
        elif prompt_c == "help":
            print "look, examine (object), n, w, e, s, take (item)"
            print
            prompt_con()
        else:
            print "That command is invalid"
            print
            prompt_con()
    except ValueError:
        print "That command is invalid."
        print
        prompt_con()

def kitchen():
    global gold  #!!!!!
    print "Current Gold = ",gold
    print '''    You are in a large kitchen. The sideboard is solid mahogany,
    but hopelessly scratched. There is a large rusted gas stove in the corner
    with what looks like a mouldy roast inside. The knife rack has a large
    and menacing array of pointy things, but in stark contrast the cupboards
    are all bare. The exits are (s)outh, (e)ast and (w)est.

    Type help for a full list of commands.'''
    print
    prompt_kit()
def kit_desc():
    print '''    The sideboard is solid mahogany, but hopelessly scratched.
    There is a large rusted gas stove in the corner with what looks like
    a mouldy roast inside.The knife rack has a large and menacing array of
    pointy things, but in stark contrast the cupboards are all bare.'''
    print
    prompt_kit()
def prompt_kit():
    prompt_k = raw_input("Type a command: ")
    try:
        if prompt_k == "s":
            main_hall()
        elif prompt_k == "e":
            conservatory()
        elif prompt_k == "w":
            dining_room()
        elif prompt_k == "look":
            kit_desc()
        elif prompt_k == "examine sideboard":
            print '''    The sideboard has been badly scratched. The wood is
            worn away to almost nothing'''
            print
            prompt_kit()
        elif prompt_k == "examine stove":
            print "The stove is broken."
            print
            prompt_kit()
        elif prompt_k == "examine roast":
            print "Eeeeewwww!"
            print
            prompt_kit()
        elif prompt_k == "examine rack":
            print "The rack is full of sharp objects. Better stay away!"
            print
            prompt_kit()
        elif prompt_k == "examine cupboard":
            print "Empty"
            print
            prompt_kit()
        elif prompt_k == "help":
            print "look, examine (object), n, w, e, s, take (item)"
            print
            prompt_kit()
        else:
            print "That command is invalid!"
            print
            prompt_kit()
    except ValueError:
        print "That command is invalid!"
        print
        prompt_kit()

def dining_room():
    global gold  #!!!!!!
    print "Current Gold = ",gold
    print '''    There is a large oak table in the centre of the room. It, unlike
    the rest of the house, is in good condition. There are 6 chairs around the table
    that must have been used for the family and their friends. There is a large vase
    in the corner that is decorated with a Salvador Dali work involving melting
    clocks. On the north wall is a family photo containing not just the father, mother
    and children but other family members too. On the west wall is a tapestry
    depicting a great battle.
    The Exits are (s)outh and (e)ast.

    Type 'help' for a full list of commands.'''
    print
    prompt_din()
def din_desc():
    print '''    There is a large oak table in the centre of the room. It, unlike
    the rest of the house, is in good condition. There are 6 chairs around the table
    that must have been used for the family and their friends. There is a large vase
    in the corner that is decorated with a Salvador Dali work involving melting
    clocks. On the north wall is a family photo containing not just the father, mother
    and children but other family members too. On the west wall is a tapestry
    depicting a great battle.'''
    print
    prompt_din()
def prompt_din():
    global gotGold_din
    global gold
    prompt_di=raw_input("Type a command: ").lower()  #!!!!!!!
    try:
        if prompt_di == "e":
            kitchen()
        elif prompt_di == "s":
            drawing_room()
        elif prompt_di == "examine table":
            print "The table is untarnished. Strange..."
            print
            prompt_din()
        elif prompt_di == "examine chairs":
            print "There are enough for the whole family and three guests"
            print
            prompt_din()
        elif prompt_di == "examine vase":
            if gotGold_din == 0:
                print "There are 4 gold pieces in the vase."
                print
                prompt_din()
            elif gotGold_din == 1:
                print "It has a picture by Salvador Dali on it."
                print
                prompt_din()
        elif prompt_di == "examine photo":
            print "An old family photo. How sweet."
            print
            prompt_din()
        elif prompt_di == "examine tapestry":
            print "It depicts a ferocious war in the year... Let's see... 26BC."
            print
            prompt_din()
        elif prompt_di == "take gold":
            if gotGold_din == 0:        # added ==  !!!!!!!!!!!
                print "You got 4 gold"
                gotGold_din = 1
                gold=gold+4             # changed to gold=gold+4  !!!!!!! 
                print
                dining_room()
            elif gotGold_din == 1:      # added ==  !!!!!!!!!!!
                print "No gold here"
                print
                prompt_din()
        else:
            print "That command is invalid"
            print
            prompt_din()
    except ValueError:
        print "That command is invalid"
        print
        prompt_din()
def ending():
    print '''    You place the coins on the doormat. The voice rings out again:
    "I thank you for gathering these coins that I lost. I need them to fix the stairs.
    I can't get upstairs if the stairs are gone, and that is where I pay my bills.
    You may go now." And with that, the bolt disintegrates, allowing the door to swing
    open and you to leave.

    THE END'''

    dummy = raw_input("Press any button to quit.")
    
start()
foyer()
Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
 

Thanks for the info. But I was already declaring all the globals within the functions that used them. I'll alter the help thing and the .lower(), and upload v1.1

chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Hi ya Chris, nice work indeed! Reads like a mystery novel!
Just a little note on global variables ...
[php]x = 77

def test1():
# this will work and print 77 without declaring x as a global
# still, it would be better to declare global x in the function
# so you have an idea where x comes from
print x

def test2():
# this works and will print 77 then print 33
global x
print x
x = 33
print x

def test3():
# this will give an error since there is also a local variable x
# UnboundLocalError: local variable 'x' referenced before assignment
print x
x = 33
print x

test1()
print
test2()
print
test3()
[/php]

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Here's the version that converts the commands to lowercase, adds help as a function called help1() and alters a few other minor oopsies that will affect the game, such as improperly lined-up nested if-elif statements.

Attachments TextAd.zip (4.38KB)
chris99
Junior Poster
118 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You