| | |
Help with text-based RPG
Please support our Game Development advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 55
Reputation:
Solved Threads: 4
Here's something that I already found after reading just a few lines.
line #254
You already have that declared on line 158, so you're not going to have that declared again.
lines #247 - #267
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
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 (^_^)
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>
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!
Thanks for the tips!
Hey, I'm just a kid
•
•
Join Date: Feb 2008
Posts: 55
Reputation:
Solved Threads: 4
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.
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.
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?
What am I doing wrong?
Hey, I'm just a kid
You should change the "< >" to quotes ( " " ):
If you want to use multiple files I would recommend that you use .h files. For example:
You have a function
Now you put
#include "bfunction.cpp" This means that the file is in de project-folderIf 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: c Syntax (Toggle Plain Text)
int foo (int number) { return number*2; }
#include "foo.h" in your main.cpp and your done! •
•
Join Date: Feb 2008
Posts: 55
Reputation:
Solved Threads: 4
I'm assuming that this is going to be on a web page.
I know that in PHP you can do things like this
Or you can also do it like phpBB does it:
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:
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.
I know that in PHP you can do things like this
PHP Syntax (Toggle Plain Text)
<?php $phpbb_root_path = './../'; include($phpbb_root_path . 'includes/functions.php'); ?>
Or you can also do it like phpBB does it:
PHP Syntax (Toggle Plain Text)
<?php $phpbb_root_path = './../'; include($phpbb_root_path . 'includes/functions.' .$phpEx); ?>
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)
#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
@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 ].
@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..
![]() |
Similar Threads
- How would I make a text adventure? (Python)
- Web-based RPG game advice needed (Game Development)
- Enhancing a Text based RPG (C++)
Other Threads in the Game Development Forum
- Previous Thread: help with making game with Gamemaker 7
- Next Thread: First person shooters in cocoa?
| Thread Tools | Search this Thread |
Tag cloud for Game Development
3d advertising ai algorithm ban c++ cambridge camera censorship china competition console development engine fov fpx game gamedevelopment gameprogramming gamer games gaming gauntanamo government graphics idaho in-gameadvertisement intel intellectualproperty l-systems laracroft larrabee lindenmayer live manhunt math mathematics matrix mercenaries microsoft mmorpg modded msn multicore naked news nintendo obama opengl palin physics pirate playstation politics processor projection ps3 rpg search selection software sony stephenhawking stocks studio technology terrorism tombraider uk videogame web wii world-of-warcraft xbox xbox-live xbox360






