Jump to content
  • Advertisement
Sign in to follow this  
Anexa85

Text-Based RPG Question

This topic is 3630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been studying C++ for a little while now and was intereted in designing a text-based rpg but I have some questions. 1.)What is the best way to handle rooms and descriptions? What is the best way to store descriptions? 2.)I was thinking of using switch to handle interpreting player commands but that seems like it would get silly if there are a lot of different commands, is there a better way to do this? I'm not trying to get anyone to program it for me, but conceptually I'm having trouble bringing ideas for this together in an efficient way. Even general answers would be appreciated, or directions to topics I should look into more so that I can figure it out. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
1. There isn't a 'best way' as far as I know. If this is your first game, it's better to make it work than finding the best way to do stuff. You can always go back and optimize later or when the game is done. For a start, it is better just to make it simple so you understand what you are doing.

2. A switch is a good choice. It's faster than a bunch of if-else stuff. You could do divide the commands even more if you like, but I don't think that would be necessary. For example:



switch(command_type)
{
case MOVEMENT:
{
switch(command)
{
case MOVE_LEFT:
{

} break;

case MOVE_RIGHT:
{

} break;

...
}
} break;

case ACTIONS:
{
case SHOOT:
{

} break;

case EAT:
{

} break;

...
} break;

...
}


Share this post


Link to post
Share on other sites
Quote:
1.)What is the best way to handle rooms and descriptions? What is the best way to store descriptions?


Storing your room information to a flat text file would be easy as well as effective. Use standard library streams to make this process easy.

Quote:
2.)I was thinking of using switch to handle interpreting player commands but that seems like it would get silly if there are a lot of different commands, is there a better way to do this?


You can use if/else statements or a large switch, both would work equally well. Alternatively, if you get a little more advanced you can store your commands in a map and link them to functions using function pointers. Then, calling a different function based upon a command is as simple as looking up the command by key in the map.

Share this post


Link to post
Share on other sites
1) I would use a library like tinyxml and store them in XML files, but you could also do binary files, or even plain text files.

2) I would implement the command pattern personally, it is pretty easy to use.

EDIT: Forgot to close quotes in a link.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!