Public Group

# Text-Based RPG Question

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

## 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 on other sites
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 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 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 on other sites
Thank you for all the replies. I'm going to check out everything mentioned.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 33
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634122
• Total Posts
3015637
×