making a text room escape game?

This is the place for queries that don't fit in any of the other categories.

making a text room escape game?

Postby lfcpaul » Wed May 22, 2013 1:02 am

I tried putting each room as a 'def' but when i done a while loop and tried calling them the getting user to search variables in them just kept printing the same thing over and over. That prob dont make sense here is an example..
Im a noob btw have only just learnt def and lists etc.

Code: Select all
import android
droid = android.Android()

print """welcome to room escape
the aim of this game is to find
100 pound."""
print "type inst for instructions."
pounds = 0

def inst()
    print """try to find the key
    to inspect an object type its
    name, to move to a different room
    type which room.e.g.type bookshelf
    to look in bookshelf, type classroom
    to move to classroom."""

def library():
    print """you are in the library
    its quite spooky in here theres
    no lighting.
    you have the frontdesk, bookshelf
    and boxes to look in.
    theres a door to the south that
    leads to the classroom."""
    bk = "bookshelf"
    fd = "frontdesk"
    bx = "boxes"
    room2 = "classroom"

def classroom():
    print """you opened the door to
    the classroom, at least theres lights
    in here.
    theres a table and cupboard to look
    around."""
    t = "table"
    cb = "cupboard"
    inst = "inst"
   
loop = 0
while loop != 1:
    library()
    command = raw_input("what would you like to do?")
    if command == bk:
        print "nothing here but some ol books."
    elif command == fd:
        print "roumaging around...aha you found 50 pound."
        pounds = pounds + 50
    elif command == bx:
        print "kid jumps out and takes some of your money."
        pounds == pounds - 10
    elif command == inst:
        inst()
    elif command == room2:
        classroom()
        command = raw_input("what you going to do:")
        if command == t:
            print """nothing on the table couldnt you
            have just looked from where you are or are
            you blind."""
        elif command == cb:
            print """yes you just got yourself 60
            pound,
            well done."""
            pounds = pounds + 60
            print """you have completed the game
            congratulations."""
            loop = 1
        elif command == inst:
            inst()
        else:
            print "thats not a command."
    else:
        print "thats not a command."
Last edited by lfcpaul on Wed May 22, 2013 2:51 am, edited 1 time in total.
lfcpaul
 
Posts: 7
Joined: Tue May 21, 2013 8:05 pm

Re: making a text room escape game?

Postby metulburr » Wed May 22, 2013 2:27 am

I have put indents in before any1 says its that.

well we cant tell what when your code does is not properly formatted in code tags

These are probably results of you just typing in the code. But you cant type in code and get it wrong, and expect that we know that is not the problem

Code: Select all
Def room1():

it is def not Def

Code: Select all
While Loop != 0

it is while and not While, and missing a colon at the end

room1() # this i think is whats wrong. Am i calling it right.

yes

for more info, we need a working example formatted in code tags, something we can copy and paste and see for ourself whats working and whats not. Also we need the whole traceback. In some cases seeing that will tell us exactly what you did wrong.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1365
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: making a text room escape game?

Postby lfcpaul » Wed May 22, 2013 2:45 am

Sorry i didnt think anyone would really understand it.
Here it is.. am i doing it right ? I get 'bk' is not defined aswell?
Thanks for answering even though it was all worded rubbish and not coded.
Code: Select all
import android
droid = android.Android()

print """welcome to room escape
the aim of this game is to find
100 pound."""
print "type inst for instructions."
pounds = 0

def inst()
    print """try to find the key
    to inspect an object type its
    name, to move to a different room
    type which room.e.g.type bookshelf
    to look in bookshelf, type classroom
    to move to classroom."""

def library():
    print """you are in the library
    its quite spooky in here theres
    no lighting.
    you have the frontdesk, bookshelf
    and boxes to look in.
    theres a door to the south that
    leads to the classroom."""
    bk = "bookshelf"
    fd = "frontdesk"
    bx = "boxes"
    room2 = "classroom"

def classroom():
    print """you opened the door to
    the classroom, at least theres lights
    in here.
    theres a table and cupboard to look
    around."""
    t = "table"
    cb = "cupboard"
    inst = "inst"
   
loop = 0
while loop != 1:
    library()
    command = raw_input("what would you like to do?")
    if command == bk:
        print "nothing here but some ol books."
    elif command == fd:
        print "roumaging around...aha you found 50 pound."
        pounds = pounds + 50
    elif command == bx:
        print "kid jumps out and takes some of your money."
        pounds == pounds - 10
    elif command == inst:
        inst()
    elif command == room2:
        classroom()
        command = raw_input("what you going to do:")
        if command == t:
            print """nothing on the table couldnt you
            have just looked from where you are or are
            you blind."""
        elif command == cb:
            print """yes you just got yourself 60
            pound,
            well done."""
            pounds = pounds + 60
            print """you have completed the game
            congratulations."""
            loop = 1
        elif command == inst:
            inst()
        else:
            print "thats not a command."
    else:
        print "thats not a command."
Last edited by metulburr on Wed May 22, 2013 3:17 am, edited 2 times in total.
Reason: added code tags
lfcpaul
 
Posts: 7
Joined: Tue May 21, 2013 8:05 pm

Re: making a text room escape game?

Postby Mekire » Wed May 22, 2013 2:55 am

Yes as metul said, you can't just go around capitalizing keywords. You shouldn't even capitalize regular variables for no reason.

In general we put CONSTANTS in ALLCAPS and we write Classes in CamelCase. This is a convention but it is expected by people that read your code. Tabs should be four spaces.

Also, bk was defined local to your function. Other functions are not aware of its existance.

Anyway... SCIENCE:
Code: Select all
def room1():
    print "blah blah blah"

def room2():
    print "jdjdndndk"

def hallway(room_dict):
    user = ""
    while user != "quit":
        user = raw_input("Select from [bdj,hhhh,quit]>")
        if user in room_dict:
            room_dict[user]()

if __name__ == "__main__":
    ROOMS = {"bdj":room2,"hhhh":room1}
    hallway(ROOMS)

-Mek
User avatar
Mekire
 
Posts: 986
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: making a text room escape game?

Postby lfcpaul » Wed May 22, 2013 1:28 pm

Dont know what your telling me 1.there is no capitals that was just when i didnt no how to code stamp.
2.i dont no what __main__ and __name__ are???
lfcpaul
 
Posts: 7
Joined: Tue May 21, 2013 8:05 pm

Re: making a text room escape game?

Postby Mekire » Wed May 22, 2013 1:44 pm

My post was written before you edited and completely changed the first post. It is good that you added code tags, but changing the content leads to responses that will not seem relevant if someone else reads the thread (forums are for everyone, not just original posters). Neither I nor metul had any way of knowing that whatever utility you used to paste it in capitalized all your lines; and as case is important we pointed out this apparent error.

Regardless, my comments on conventions are just as valid.

As for:
Code: Select all
if __name__ == "__main__":
This is how you should place code in a module that is intended to run when that module is ran as main, but not otherwise.

__name__ will equal "__main__" for a module that is--you guessed it--being run as main. Otherwise it will be the file name (not including extension) of the module it refers to.

-Mek
User avatar
Mekire
 
Posts: 986
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: making a text room escape game?

Postby lfcpaul » Wed May 22, 2013 1:51 pm

Ok so if i write if __name__ is __main__ then do the while loop the way i did it will it work then.
If that makes sense to you?
Sorry about the changing of posts. Thought it would be helpful.
lfcpaul
 
Posts: 7
Joined: Tue May 21, 2013 8:05 pm


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests

cron