Help with text-based RPG

Please support our Game Development advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 8
Reputation: kidprogrammer is an unknown quantity at this point 
Solved Threads: 1
kidprogrammer's Avatar
kidprogrammer kidprogrammer is offline Offline
Newbie Poster

Help with text-based RPG

 
0
  #1
Feb 4th, 2008
Hey I'm new to programming but I know enough now that I have been trying to program my own game. I works, but I think my code is too complicated. Does someone want to test it and give me some suggestions? Thanks!
Attached Files
File Type: cpp scifigame.cpp (29.3 KB, 40 views)
Hey, I'm just a kid
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 55
Reputation: Suetan is an unknown quantity at this point 
Solved Threads: 4
Suetan Suetan is offline Offline
Junior Poster in Training

Re: Help with text-based RPG

 
0
  #2
Feb 4th, 2008
I'll check it out, and see what I can come up with to help you out. I'll try debugging it, as well. Please note that my knowledge in C++ is limited, but I'm starting college on March 3rd for video game programming. I'll let you know if I come up with anything.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 8
Reputation: kidprogrammer is an unknown quantity at this point 
Solved Threads: 1
kidprogrammer's Avatar
kidprogrammer kidprogrammer is offline Offline
Newbie Poster

Re: Help with text-based RPG

 
0
  #3
Feb 4th, 2008
Cool thanks!
Hey, I'm just a kid
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 55
Reputation: Suetan is an unknown quantity at this point 
Solved Threads: 4
Suetan Suetan is offline Offline
Junior Poster in Training

Re: Help with text-based RPG

 
0
  #4
Feb 4th, 2008
Here's something that I already found after reading just a few lines.

line #254
player.health = player.str * 10;

You already have that declared on line 158, so you're not going to have that declared again.

lines #247 - #267
if(playerexp >= 50)
{
	  player.lvl++;
	  player.str++;
	  player.acc = player.acc + 0;
	  player.intell++;
	  player.adrenaline = player.intell * 10;
	  player.health = player.str * 10;
	  cout << "Congratulations, you gained a level! You have gained\n";
	  cout << "1 Strength\n";
	  cout << "0 Accuracy\n";
	  cout << "1 Intelligence\n" << endl;
	  cout << "Your new stats are: " << endl;
	  cout << "Level: " << player.lvl << endl;
	  cout << "Strength: " << player.str << endl;
	  cout << "Accuracy: " << player.acc << endl;
	  cout << "Intelligence: " << player.intell << endl;
	  cout << "Health: " << player.health << endl;
	  cout << "Adrenaline: " << player.adrenaline << endl << endl;
	  system("PAUSE");
}

I'd just have that be in a module that you'd call at the beginning of the file. It could be in something like functions.cpp. Once you have the module created, you'd replace that code with the following
if neededexp = 0
{
     levelup();
}
else
{
     neededexp = neededexp - expgained;
}

The repeated battle animations can be cut from this file, and put into a function that would be in functions.cpp

lines #319 - #795

Cut them out of this file entirely, and make them a part of functions.cpp and include them at the beginning of this file. It'll save you a lot of time that way.

With your comments, just have them be like this:

// whatever

and the at the end of the code that is commented

// end whatever

This will make it so that the computer has to read less code, which will optimize loading times.

That's just what I've found just by skimming over your file quickly. #include <functions.cpp>;
should make it so that your load times will be smaller, and it'll also make it so that you don't have to keep repeating the same code over and over.

I hope that I helped you out.

Good luck, man (^_^)
Last edited by Suetan; Feb 4th, 2008 at 9:09 pm. Reason: Added comment remarks, and fixed #inculde <functions.cpp>
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 8
Reputation: kidprogrammer is an unknown quantity at this point 
Solved Threads: 1
kidprogrammer's Avatar
kidprogrammer kidprogrammer is offline Offline
Newbie Poster

Re: Help with text-based RPG

 
0
  #5
Feb 4th, 2008
Ya, I modularized a bunch of the code today, including the leveling part you were explaining. I'll go through the battle function and look for repeated/unnecessary code. I didn't know you could include your own functions written in other files, so I'll expirement with that too.

Thanks for the tips!
Hey, I'm just a kid
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 55
Reputation: Suetan is an unknown quantity at this point 
Solved Threads: 4
Suetan Suetan is offline Offline
Junior Poster in Training

Re: Help with text-based RPG

 
0
  #6
Feb 4th, 2008
Hey, no problem. I'm just glad that I was able to help.

I don't know if you're old enough to go to college (or even in USA), but if you are, you might want to think about going to DeVry for their online game and simulation programming courses. I'm doing that starting in March.

Thanks for letting me help you out.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 8
Reputation: kidprogrammer is an unknown quantity at this point 
Solved Threads: 1
kidprogrammer's Avatar
kidprogrammer kidprogrammer is offline Offline
Newbie Poster

Re: Help with text-based RPG

 
0
  #7
Feb 5th, 2008
Ok, I tried putting the battle function in a new file and #including it into the main file, but it tells me that there is no such file or directory when I try to compile. The name of the function file is bfunction.cpp and in the main file I am including it like so: #include <bfunction.cpp>
What am I doing wrong?
Hey, I'm just a kid
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,968
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Help with text-based RPG

 
0
  #8
Feb 5th, 2008
You should change the "< >" to quotes ( " " ):
#include "bfunction.cpp" This means that the file is in de project-folder


If you want to use multiple files I would recommend that you use .h files. For example:

You have a function void foo(int number) { } You put de declaration in the header file (foo.h):
int foo (int); Next you put the implementation in the foo.cpp file:
  1. int foo (int number)
  2. {
  3. return number*2;
  4. }
Now you put #include "foo.h" in your main.cpp and your done!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 55
Reputation: Suetan is an unknown quantity at this point 
Solved Threads: 4
Suetan Suetan is offline Offline
Junior Poster in Training

Re: Help with text-based RPG

 
0
  #9
Feb 5th, 2008
I'm assuming that this is going to be on a web page.

I know that in PHP you can do things like this

  1. <?php
  2. $phpbb_root_path = './../';
  3. include($phpbb_root_path . 'includes/functions.php');
  4. ?>

Or you can also do it like phpBB does it:

  1. <?php
  2. $phpbb_root_path = './../';
  3. include($phpbb_root_path . 'includes/functions.' .$phpEx);
  4. ?>

You will have to declare the root directory before you're able to do any including in PHP.

Since PHP is based off of C++, you might be able to do it something like this:

  1. #include "functions/bfunction.cpp";

Like I said, I have limited knowledge of C++ right now, so I'm not guarenteeing that anything will work exactly how you want it to, or at all for that matter.
Last edited by Suetan; Feb 5th, 2008 at 3:48 pm. Reason: relocated some text to make it coinside with code samples
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Help with text-based RPG

 
0
  #10
Feb 5th, 2008
@Suetan, since the original poster's code is C++, I sincerly doubt that the means for performing a PHP include will be much help... PHP isn't a subset/superset of C++ : PHP is parsed by and interpretted by a C++ runtime engine; if that's what you mean by 'based off of C++'.

@kidprogrammer, it looks good to me. Perhaps some of the stuff in main could be moved out into other functions; but only if it looks like you'll gain any benefit, and not have many costs ( i.e. having to pass more than about 8 parameters to a 10 line function, or a function that's only called from one place is too many costs ).

Also, a minor; you use the windows.h header only for the 'Sleep' function.. That means your program will only compile on Windows machines, even though most of the code is platform-neutral. If you're only targeting Windows, that's fine. There are other ways to do a sleep( n ) though [ i.e, you should be able to use a call to system( "sleep n" ) and thus cut out the dependancy on windows.h ].
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Game Development Forum
Thread Tools Search this Thread



Tag cloud for Game Development
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC