943,895 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Feb 4th, 2008
0

Help with text-based RPG

Expand Post »
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, 133 views)
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kidprogrammer is offline Offline
8 posts
since Feb 2008
Feb 4th, 2008
0

Re: Help with text-based RPG

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.
Reputation Points: 11
Solved Threads: 5
Junior Poster in Training
Suetan is offline Offline
75 posts
since Feb 2008
Feb 4th, 2008
0

Re: Help with text-based RPG

Cool thanks!
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kidprogrammer is offline Offline
8 posts
since Feb 2008
Feb 4th, 2008
0

Re: Help with text-based RPG

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>
Reputation Points: 11
Solved Threads: 5
Junior Poster in Training
Suetan is offline Offline
75 posts
since Feb 2008
Feb 4th, 2008
0

Re: Help with text-based RPG

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!
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kidprogrammer is offline Offline
8 posts
since Feb 2008
Feb 4th, 2008
0

Re: Help with text-based RPG

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.
Reputation Points: 11
Solved Threads: 5
Junior Poster in Training
Suetan is offline Offline
75 posts
since Feb 2008
Feb 5th, 2008
0

Re: Help with text-based RPG

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?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kidprogrammer is offline Offline
8 posts
since Feb 2008
Feb 5th, 2008
0

Re: Help with text-based RPG

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!
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Feb 5th, 2008
0

Re: Help with text-based RPG

I'm assuming that this is going to be on a web page.

I know that in PHP you can do things like this

PHP Syntax (Toggle Plain Text)
  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:

PHP Syntax (Toggle Plain Text)
  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:

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 11
Solved Threads: 5
Junior Poster in Training
Suetan is offline Offline
75 posts
since Feb 2008
Feb 5th, 2008
0

Re: Help with text-based RPG

@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 ].
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: help with making game with Gamemaker 7
Next Thread in Game Development Forum Timeline: First person shooters in cocoa?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC