|
-
Mar 31st, 2003, 10:23 PM
#1
Thread Starter
Junior Member
Making a text RPG, and having trouble with movement between rooms
I already have the battle engine guts worked out, and I have a plan about how to move around. However, I cant figure out the best way to move from room to room. The character is going to have a choice to go N S E or W in each room.
I originally planned having each room in its own function, but I decided against that because they would be calling each other indefinatly, and therfore I couldnt end the program (cant end the program if you cant call return 0; on main()). Now, however, I cant really decide how I should do this. Insights or advice, please?
-
Apr 1st, 2003, 04:27 AM
#2
transcendental analytic
one easy way would be to let main call the function for the first room and let all functions return a function pointer to the room to enter room when exiting a room, and null pointer when ending the game, and let main keep on calling the returned functions unless they return 0.
In the long run it might get tedious and the code will bloat the program and you'd rather look into making a script driven engine.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 1st, 2003, 09:26 AM
#3
Monday Morning Lunatic
Make a graph of rooms. Each room has four variables (N, S, E, W), or more if you choose more directions. Each of these is either a pointer to a room, or NULL.
If you want to apply some kind of logic to this (you cannot go north if you don't have a room key, for example) then you would need to check this when moving (each node knows what prerequisites are needed, because you define them in some kind of map file).
Alternatively, you could go for Kedaman's suggestion (IMO the more ideal and more flexible, if a little more effort to implement) of scripting all of this. Thus you would have a "default" action for movement, which is to allow the movement if there is a link between the rooms defined. You could then specialise that for individual rooms.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|