My text Adventure game need help

My text Adventure game need help

Postby dragonlypse » Thu Apr 21, 2016 4:52 pm

I am a student in college, im learning python but my teacher sucks and I am more or less self learning. I am trying to make a text based game to begin with and I am struggling. I dont even think I have anything here but here is my code. Any help is welcomed
-Nikki
Code: Select all
##Survive the school
import random
import time


def start():
    print ("Welcome to Survive the school:Outbreak ")
    time.sleep(2)
    print ("You and 2 other students are in detention.")
    time.sleep(2)
    print ("The lights went out and you hear screams.")
    time.sleep(2)
    print ("You need to find your way through the school to escape.")
    time.sleep(2)
    print ("Find the principles keys and unlock the exit in the gym.")
    time.sleep(2)
    print ("Dont get caught by a zombie, you might die or get infected.")
    global keys
    keys = 0
    room1()
    room2()
    room3()
    room4()
    room5()
    room6()
    room7()
    room8()
    office()
    lunchroom()
    gym()
    lockerroom()

def promt():
    x = raw_input("type a command: ")
    return x

def currentKeys():
    global keys
    print ("Current Keys =") , keys

def room1():
    global keys
    print (" You are in the detention room ")
    print (" Exit the room in a direction, north, west, south, east commands will take you.")
    command = promt()
    if command == "NORTH":
        print ("The doors are chained, you can not go that way!")
        time.sleep(3)
        print ("Pick another direction.")
    if command == "SOUTH":
        print ("You need to check the room accross the hall before you can move on")
        time.sleep(3)
        print ("Pick another direction.")
    if command == "EAST":
        print ("The windows are sealed, you cannot break them or you will draw attention.")
        time.sleep(3)
        print ("Pick another direction.")
    if command == "WEST":
        print ("you open the detention room door and see lights flickering.")
        time.sleep(3)
        print ("you and your classmates tip toe accross the hallway and entrer room 202.")
        if command == "WEST":
        room2()
   
    elif command == "keys"
        currentKeys(0)
        room1()
    else:
        room1()
       
def room2():
    global keys
    print ("you have entered room 202, you look around and see 3 bodies.")
    time.sleep(3)
    print ("you look at your friends and they want you to figure out what to do.")
    time.sleep(3)
    print ("Your friend wants you to search the bodys, you can search by typing SEARCH.")
    command = prompt()
    if command == "SEARCH":
        keys = keys + 1
        currentKeys(1)
        print ("You have found a key, not sure if its the one we need, you now have 1 key")
        elif command == "keys":
        currentKeys(1)
    if command == "NORTH":
        print ("Dont want to go back!")
        time.sleep(3)
        print ("Pick another direction!")
    if command == "WEST":
        print ("Nothing west but windows")
        time.sleep(3)
        print ("Pick another direction")
    if command == "EAST":
        print ("You look out the door and see a room accross the hall and a room to the right")
        time.sleep(2)
        print ("It looks clear and you head across the hall to room 203")
    if command == "SOUTH":
        print ("You look out the door and see a room accross the hall and a room to the right")
        time.sleep(2)
        print ("It looks clear and you head across the hall to room 203")
        if command == "SOUTH":
        room3()
        if command == "EAST":
        room3()
       
    elif command == "keys":
        currentKeys(1)
        room2()
    else:
        room2()



def room3():
    global keys
    print ("you have entered room 203, you look around and see 1 Back Pack.")
    time.sleep(3)
    print ("you look at your friends and they want you to figure out what to do.")
    time.sleep(3)
    print ("Your friend wants you to search the Back Pack.")
    command = prompt()
    if command == "SEARCH":
        keys = keys + 1
        currentKeys(2)
        print ("You have found a key, not sure if its the one we need, you now have 1 key")
        elif command == "keys":
       
    if command == "NORTH":
        print ("Dont want to go back!")
        time.sleep(3)
        print ("Pick another direction!")
    if command == "WEST":
        print ("You look out the door and see a room accross the hall and a room to the Left")
        time.sleep(3)
       print ("It looks clear and you head across the hall to room 204")
    if command == "EAST":
        print ("Nothing but windows")
        time.sleep(2)
        print ("pick another direction")
    if command == "SOUTH":
        print ("You look out the door and see a room accross the hall and a room to the Left")
        time.sleep(2)
        print ("It looks clear and you head across the hall to room 204")
        if command == "SOUTH":
        room4()
        if command == "EAST":
        room4()
    else:
        room3()


        start()
Last edited by Yoriz on Thu Apr 21, 2016 5:35 pm, edited 1 time in total.
Reason: First post lock. Added code tags.
dragonlypse
 
Posts: 1
Joined: Thu Apr 21, 2016 4:50 pm

Re: My text Adventure game need help

Postby Ofnuts » Thu Apr 21, 2016 7:48 pm

Maybe listen more to your teacher.

Word of advice: text-based games are dangerous... Beginners without any knowledge of software design do it the wrong way (and you are no exception:)) and end up very quickly with an unmanageable mess. The right way involves not much code but lots of (cleverly organized) data. Instead of focusing on the differences between the rooms, consider what they have in common:
  • 2 to 4 other rooms to which they are connected
  • one description message
  • something to do (pick up object, fight monster, fall in pit...)
  • etc...
So what they have in common is a "structure", that translates to common code for all rooms, and what is different is the details, which is kept in data. So your code ends up being a single not-that-big function that looks at the data of the current room (display message, get the user action choice, move to the next room, etc...). An evolved code such as this is called an "engine". You can radically change the game by just changing the data while keeping the engine.

Programming is finding the simplicity in things...
Last edited by Ofnuts on Thu Apr 21, 2016 9:59 pm, edited 1 time in total.
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987

Re: My text Adventure game need help

Postby micseydel » Thu Apr 21, 2016 8:09 pm

Ofnuts' answer was very good, but I thought there was a bit more to say...

When trying to solve a problem, you should identify the problem clearly. We (experienced programmers) can quickly get a feel for how manageable, readable, maintainable, etc. your code is, but you should still define your problem as clearly and objectively as you can.

Are you not getting a result you desire? What result do you expect? What are the precise steps to reproduce the problem?

Are you not sure how to tackle getting a new result? Give it a try. Do the same thing as above.

In any case, it's ideal to ask a question. That means a question mark, and not a question like "any thoughts?" or "how do I do this?" An example of a good question might be, "How can I share a variable like keys between multiple rooms with the global keyword?"
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: My text Adventure game need help

Postby Onager » Thu Apr 21, 2016 9:42 pm

Your code is procedural, and in Python that does't really work for anything except short snippets. Something like a text game would be too complex for a procedural approach to work. You need to take an objective-oriented approach or pick a different language. (Scheme is a good procedural language, but I don't know whether it would be suitable for your project.)

And if you don't know what "procedural" and "objective-oriented" mean, well, I've got some bad news: learning programming involves a crapton of finding things out for yourself. Experienced programmers especially hate to be asked basic questions that you could find answers for with a little googling, and expecting anyone to hold your hand while learning programming will just make that person an enemy. Word to the wise.
Onager
 
Posts: 13
Joined: Wed Apr 20, 2016 11:25 pm

Re: My text Adventure game need help

Postby micseydel » Thu Apr 21, 2016 10:10 pm

Onager wrote:in Python [procedural code] does't really work for anything except short snippets.

Hm? Python is multi-paradigm. I'm of the opinion OOP is great and well-suited to this task, however it can be done procedurally and OOP can be intimidating for beginners (and offers a whole other set of mistakes to be made) so I believe building a solid procedural text adventure game is fine. Could you elaborate further?

Onager wrote:(Scheme is a good procedural language, but I don't know whether it would be suitable for your project.)

Perhaps you're more familiar with Scheme that I am, but a quick search indicates that, like Python, it's multi-paradigm. My (admittedly superficial) understanding would be that Scheme would only really be preferable to Python if you wanted solid functional support (Python's functional support, while present, is weak). What specifically about Scheme do you believe makes it worth recommending on a Python forum?
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: My text Adventure game need help

Postby Ofnuts » Thu Apr 21, 2016 10:12 pm

Onager wrote:(Scheme is a good procedural language)
***Falls off the chair***

Onager wrote:And if you don't know what "procedural" and "objective-oriented" mean
Neither do I. Objective oriented? You mean goal-based, like Prolog? Or is that "object-oriented"?

Onager wrote:, well, I've got some bad news: learning programming involves a crapton of finding things out for yourself. Experienced programmers especially hate to be asked basic questions that you could find answers for with a little googling, and expecting anyone to hold your hand while learning programming will just make that person an enemy. Word to the wise.

Experienced programmers who don't like to be asked simple things just don't show up in forum such as this one... Googling is fine when you know what you are looking for, and have enough experience to take some answers with the required grain of salt. But the rank beginner doesn't even know what question to ask...
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987

Re: My text Adventure game need help

Postby Onager » Fri Apr 22, 2016 12:03 am

I'm no expert on anything, just a guy who's gone around the block 1,024 x 1,024 times and is still going around the block.

I apologize for sounding like I was "recommending" Scheme. And it's very well known socially among programmers that procedural code labels you as a beginner who doesn't know what he's doing. In fact, that's one approach programmers use to identify beginners--and, of course, beginners are not informed of this. It's a social issue within programming.
Onager
 
Posts: 13
Joined: Wed Apr 20, 2016 11:25 pm

Re: My text Adventure game need help

Postby micseydel » Fri Apr 22, 2016 12:09 am

We're happy recommend OOP to a beginner once they get some experience. This student who's struggling with their teacher doesn't need OOP right now, procedural is just fine. If they're still interested in programming after their course, we'll certainly recommend OOP more heavily.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: My text Adventure game need help

Postby Ofnuts » Fri Apr 22, 2016 7:33 am

Onager wrote:I'm no expert on anything, just a guy who's gone around the block 1,024 x 1,024 times and is still going around the block.

I apologize for sounding like I was "recommending" Scheme. And it's very well known socially among programmers that procedural code labels you as a beginner who doesn't know what he's doing. In fact, that's one approach programmers use to identify beginners--and, of course, beginners are not informed of this. It's a social issue within programming.


If you code in C, procedural is all you can do, even if there are libraries to help you "objectify" your code. And C is hardly for beginners these days.

And I wonder where you got the idea that programmers don't like beginners?
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987


Return to Game Development

Who is online

Users browsing this forum: Bing [Bot] and 1 guest