Jump to content
  • Advertisement
Sign in to follow this  
thatscientificgeek

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

This topic is 2584 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

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.

Link for source code:
http://dl.dropbox.com/u/43033918/FirstGame.cpp

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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.

Link To Latest RPG Source

Share this post


Link to post
Share on other sites

This topic is 2584 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.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!