Sign in to follow this  
valsar

Quick quesiton about text based rpgs

Recommended Posts

I'm programming a text based rpg using C/C++ and I was wondering what's a good way for calling the rooms. Should I use recursion or should I do it using a diffrent method. Any help would be nice. If you need more information, just ask.

Share this post


Link to post
Share on other sites
Say there are 4 rooms.
[1]
|
[2]-[3]-[4]

As an example, you start in room 1, when you go to room 2, it calls the room2 function, and when you go to room 3 it calls the room 3 function. The other two rooms are still on the stack. Then when you exit the program, all the functions return 0 and take themseleves off the stack one by one until the program closes.

Is there a better way of calling the rooms.

I hope this helped explain what I was trying to ask the first time.

Share this post


Link to post
Share on other sites
If you have a bunch of functions representing the rooms the user is in and you call them each... then you're going about it the wrong way. What you really want is a data file containing descriptions of the rooms, items in the rooms, things that can be changed in the rooms, places you can go in the rooms.

Look at one room description I just made up:

Room: Lion's Den

You stand in a large room filled with the bones of past travelers, causing your own bones to quiver in fright. You can hear a low moan coming from the door to the east. To the north there is bright light filtering in. There is a key on the floor.

What will you do? look at bones

There are skulls, themurs, legs, etc of dozens of travelers.

What will you do? pick up key

You have picked the key up.

What will you do? Look at room

You stand in a large room filled with the bones of past travelers, causing your own bones to quiver in fright. You can hear a low moan coming from the door to the east. To the north there is bright light filtering in.


So what have we discovered? Well, there are objects like the bones that you can't pick up, but you can look at like the bones. And there are objects you can pick up and you can look at like the key. There are pathways. Let's say that a room is filled with objects that 'know how to talk about themselves'

So a room will have information about doorways, and objects. And the objects will know what they look like and what you can do with them. The trick is knowing how to store this information in a file and how to load it when you get to a room. You could maybe have one file per room, or figure out how to put it all in one file.

Here's a data format I just invented:
room: Lion's Den
doors:
east:
description: You can hear a low moan coming from the door to the east
move: When you try to move to the door you become paralyzed with fright
north:
description: To the north there is a bright light filtering in
move: GoTo: The Room of Light
objects:
key:
description: This key is large and red like blood...
pick up: You have picked the key up
bones:
description: There are skulls, themurs, legs, etc of dozens of travelers.

room: The Room of Light
...



And when you pick up the key the program will delete the key object from the room. Basically based on the attributes of the items the computer will figure out what to do when the user performs an action. Look at [item] will print the description given, and if you say pick up, or grab, or take the item... it will print what's shown under "pick up" along with altering the file.

This is by far not a great data format, it's just something to get you thinking about the problem. Hope this helps.

Share this post


Link to post
Share on other sites
nobodynews: Ok. I understand what your saying, I'm just not sure how to go about doing that. I don't think I was taught that yet in college. Any code snippets or anything would be nice.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this