Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Help with RPG Text Adventure

This topic is 5437 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''m fairly new to programming and was just wondering what would be the best way to setup the part of the program that handles the commands?

Share this post

Link to post
Share on other sites
If your talking about commands that the player gives during the main game such as "west", "sleep", "inventory", I believe the simplest way would be using a switch/case system with strings in your main game loop.

For Example...

ShowStats(); // shows stats(health,str..), x/y pos
ShowMonster(); // shows monsters on x/y grid

int GetInput()
string command;
cout << "Enter command:\t";
cin >> command;
switch(command) {
command "west": x--; break;

Share this post

Link to post
Share on other sites
It seems like it would make your life easier to tokenize all the input first - as in, convert the words to an array of enumerated integers so that checking the input is much easier.

So, step 1, write a list of all the words your program will ever use, and put them in an enumeration (or maybe a file if they get too big), like maybe this:


Then step 2, write the tokenize function that looks at the player''s string input, and figures out what words are in there. Depending on what language you are using, there are probably string tokenization things available. Break up the string by spaces, then have a big switch statement where you compare each word to your long list of words. Probably it would be good to have a token called T_UNKNOWN, for when you don''t recognize something.

Then step 3, in your main game loop you can just do something easy like this:

switch(tokenized_inputs[0]) {
  case T_INVENTORY: displayInventory(); break;
  etc etc..

Also, I remember I gave this advice to someone but I don''t remember if it was you... consider programming in Inform or TADS. They take care of these things for you.

Share this post

Link to post
Share on other sites
How would I control user input and room locations using classes? I can''t find anything on programming text-based games. ( Maybe because it''s easy for other people?) I''m using C++ and I just can''t seem to understand how to put this all together.

Share this post

Link to post
Share on other sites
I am just starting to learn programming and i want to make Text Based RPG''s like Race War Kingdoms. I have a few books about programming in basic but im still lost. (This message is to the author of the post mainly.) if your willing to help me or anyone for that matter learn this it would be apreciated.

Share this post

Link to post
Share on other sites
www.codeproject.com for a few parsing options

As to 'how to use classes for xyz'.

Try the old pen and paper approach. Draw what you think are the main building blocks of your program and then make a list of what each of them needs to remember and do and what needs to pass between them. You will then have a basic class list with variables and methods.

A collection of rooms
add a room
remove a room

A room
read description

Not a lot of help I know but it is a good starting place.

Good luck.


[edited by - baelwrath on November 27, 2003 10:30:04 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!