• Advertisement
Sign in to follow this  

Text RPG in C++

This topic is 4795 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 planning on making a text turn based RPG game to practice some programming concepts. My Plan is to have a Player class with all the player stats as well as functions to save, load and view the stats of the character. It will also have a function called Turn()to take care of options you have each turn such as exploring, fighting or other things. I'm thinking of making a menu class as well that has options to make a new game, save game, load game and quit. I'm having a hard time visualizing it as a modular program where each class is independent from any others. How would you guys structure a turn based RPG? I would like to learn how to properly structure a program that makes sense and is reuseable.

Share this post


Link to post
Share on other sites
Advertisement
It depends what you want. Do you want to have a text based, ASCII map? Do you want an AI, or will it be only player to player? If you have an AI, do you plan to read the AI attributes (skills, etc.) from a config file, or will it be hard coded?
I do only procedural (C) programming, but if I'd want classes I guess I'd have a player class, a display class, a config readign class, AI class, I/O class...

Share this post


Link to post
Share on other sites
In my text-rpg (which is almost done .. so very close .. ), I have player, enemy, weapon, armor, item, magic, etc. classes. To keep these classes independent of each other is pretty hard to do as you'll probably have player classes referencing other classes (like armor, weapons, and so on). For example, in my enemy AI code, the enemy depends on the functionality (or definition) of the weapon class, and some changes to the weapon class require me to change some code in the enemy AI code - so in that sense, it's nearly impossible to keep those classes independent of one another.

As far as the structure of a text-based RPG, it's like Raduprv said: "It depends on what you want." But since you're asking how others would do it, I'll share my thoughts on it. I won't say how my RPG is exactly structured (since it's fairly complicated in how it works), but for a general turn-based text RPG I'd use a player and enemy class (each possibly derived from a base class), item classes that those players and enemies need such as weapons, armor, drinkable and usable items, etc. (each possibly derived from a base class), and a combat manager class for maintaining the flow of combat between the player and enemy classes. Once the combat part of the game is done, I'd move on to getting the players to move around in the world. My game uses point and area classes to define the world (they form a graph of sorts, but not really .. it's complicated ... ), but you could use an ascii map like Raduprv mentioned or some other method. Once that's done, I'd make a game manager class that serves to connect the two together - for example, the world class (or whatever class that deals with the players moving around) might send a message to the game manager that says the players should now be engaged in combat, and so the game manager would fire up the combat class, wait for combat to finish, then go back to the world class. Once you have all that done, you'd need a way to save data (and load data) either using the game manager or a resource manager (like my game uses) that the game manager class calls upon.

Anyway, hope that helps a bit. If you use the "structure" I outlined above, you'll get some pretty decent practice on programming concepts. I've learned quite a bit while working on mine. Good luck!

Share this post


Link to post
Share on other sites
Quote:
Original post by Sabonis
I'm planning on making a text turn based RPG game


did i hear this right? a "turn-based" text-based RPG? As in you only have a certain amount of turns each day to move, fight, examine, use items, and stuff. If this is what you meant you may want to look at the disadvantages of having a "turn-based" game.

First of all, having a turn-based games with a limited number of turns each day limits the time the player will spend on your game. This actually annoys the heck out of me.

Secondly, ppl WILL get tired of having to log in everyday just to play a few minutes before logging back out and waiting for more turns the next day. This also bugs the heck out of me.

Basically, what i want to know is, IS there an advantage of doing a turn-based game. and do these advantages out-weight the disadvantages.

Im not trying to harp all over your idea, just want to help make sure you know the drawbacks of turn-based games before you spend the effort of making one.

Share this post


Link to post
Share on other sites
Quote:
Original post by FridgeRaider

did i hear this right? a "turn-based" text-based RPG? As in you only have a certain amount of turns each day to move, fight, examine, use items, and stuff. If this is what you meant you may want to look at the disadvantages of having a "turn-based" game.

First of all, having a turn-based games with a limited number of turns each day limits the time the player will spend on your game. This actually annoys the heck out of me.

Secondly, ppl WILL get tired of having to log in everyday just to play a few minutes before logging back out and waiting for more turns the next day. This also bugs the heck out of me.

Basically, what i want to know is, IS there an advantage of doing a turn-based game. and do these advantages out-weight the disadvantages.

Im not trying to harp all over your idea, just want to help make sure you know the drawbacks of turn-based games before you spend the effort of making one.


Umm, he said RPG, not MMORPG.

Share this post


Link to post
Share on other sites
Put all general code in a CEngine class. Then, individual items, like enemies, inventory items, inventory itself, etc. should be in their own independent classes (EDIT: but instantiated (put) inside the CEngine class, so that CEngine would have access to everything, as well it should, since CEngine is usually the "master of all classes").

Of course, these classes will never be truly independent. They communicate with each other, work together, to make the game "happen". That imposes some restrictions on what you must have in classes.

Anything that can be treated as an individual unit should be in its own class, even if it is physically abstract (such as the engine, AI, menu - as well as "physical" items like player, enemy, etc.)

It's also important to plan the structure of your game out - write down what you want in classes before you start. Obviously, you'll make changes - it's hard to visualize an entire game before starting. But it would help greatly with preliminary coding and such.

Also, when you're doing this, try to think of any dependencies, such as the CEnemy class would have to have access to the map so it can decide where to move, and if it would be able to move at all. A CMap class would need access to the CTile class so it could create an array of it (for the map. This is, of course, if you decide to have a CTile class at all.) Realizing these dependencies helps greatly in implementation.

Lastly, a million coders could give you much advice, but that's nothing compared to the experience you gain from designing your own game (without excessive copying of book/article examples, of course!).

Share this post


Link to post
Share on other sites
The guy above me posted alot better then I was going to but I'm still gonna get my 2 cents in.
Classes shouldn't be completely independent of eachother. How would a program work? The concept of encapsulation is best described by this imagery: think of every class as a black box that is connected to another class by a very thin cord. The box is invincible and you cannot find what is inside the box unless you use the cord to tell it to tell you what is inside.
A class's private properties are independent of all outside code and you should not readily create a situation that allows this. The public properties give you a layer to access (indirectly) the private properties.
Anyways, just understand proper encapsulation should be like a spider web.

Share this post


Link to post
Share on other sites
Ok I'm going to try and make a cEngine class with all the functionality and have the other classes within it so it has all the access it needs.. Thanks for your help guys! I will post the game up sometime so you can all check it out

Share this post


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

  • Advertisement