Public Group

developing a text based rpg (please review my code an help me)

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

Recommended Posts

Hi, I am the owner of VIsIn games and I have just finished my book on C++. I am still learning a lot though and decided to put what I've learned into a fun game for people. Please try this out and tell me if there's anything I can do to improve it. (There probably are some major flaws!). This is a work in progress and I am definitely still developing it.

http://dl.dropbox.com/u/43033918/FirstGame.cpp

Share on other sites
Well, a conceptual problem is that the ogre's health never goes to zero. Suppose you attack two times, you'll go into the first if statement because 10 > 2, but then ogrehealth becomes 9 when you supposedly dealt 8 damage. Secondly, you never actually check to see if ogrehealth == 0.

Ok, now for some advice. A basic book on C++ will teach you about loops. I would suggest doing something like:
 while(ogrehealth > 0){ ... //code } std::cout << "Ogre is dead" << std::endl; 

Later on, you will learn that local variables with long names aren't too much of a help and will eventually become a burden. A suggestion would be:
 struct entity { float health; }; 

This is so that in your main program, you can be like:
 entity player; entity ogre; player.health = 20; ogre.health = 10; 

Additionally, using system("pause") will output "Press any key to continue..." and works nicely. You can also add "using std::cout" and "using std::cin" so you only have to write cout or cin.

A key factor in game development is creating easily maintainable code. Remember that, and happy coding.

Share on other sites
I know that, and I tried that. I'll try again though.

Share on other sites
For some reason whenever I use while loops (i didnt do it because I tried it before) my program stops at the while loop and doesnt go on. Please HELP.

Share on other sites

For some reason whenever I use while loops (i didnt do it because I tried it before) my program stops at the while loop and doesnt go on. Please HELP.

Post the code just before and through the while loop, and someone will be able to help you.

Just saying, "it doesn't work, help!" isn't helpful at all.

Share on other sites

For some reason whenever I use while loops (i didnt do it because I tried it before) my program stops at the while loop and doesnt go on. Please HELP.

Your program stops at the while loop because you called the end of the loop immediately after declaring it. Remove the semicolon placed after the second parenthesis in the while loop declaration and it should run fine.

while (ogrehealth > 2);{ ogrehealth--; }

What this should be is:

while (ogrehealth > 2){ ogrehealth--; }

If your really trying to develop a text based RPG then I recommend you check out the thread for my text based RPG. The complete source is available to download. Most of the comments are up to date and it should give you a reference to work off of.

Share on other sites
I figured that out myself like five minutes before reading that post, but thank you! it works perfectly now!

Share on other sites
OP started a new thread and this thread appears resolved. So, closing this one.

Share on other sites

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

This topic is now closed to further replies.

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 23
• 38
• 75