Quick quesiton about text based rpgs

Started by
6 comments, last by valsar 18 years, 9 months ago
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.
Advertisement
More info please. :)

What do you mean by "Calling"? Like, a string? Do you mean like naming them? You'd probably want to read them in by file.
-----If you thought I was helpful, rate me down.If you thought I wasn't helpful, rate me down as well.This idiot didn't read my signature and tried to insult me.
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.
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 Dendoors: 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 Lightobjects: 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.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Yes yes this is the way to do such things.
-----If you thought I was helpful, rate me down.If you thought I wasn't helpful, rate me down as well.This idiot didn't read my signature and tried to insult me.
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.
Have you done file i/o? And have you worked with classes/structs?
I've worked with classes and structs alot, and I've worked with file i/o a little bit.

This topic is closed to new replies.

Advertisement