Help Wanted

C++ Questions... – mellonamin

mellonamin

Member

Posts: 119
From: Maryville, TN, United States
Registered: 11-16-2004
I have a few questions about C++ if anyone would mind answering them...

1. How can I convert a string of text to all uppercase or all lowercase?

2. How can I split my source code for a game up into different files and still use functions from each of them in any file? Right now I have like 25 different functions within about 700 lines of file and it is getting kind of confusing...

3. How can I get multi-word strings from a user and then execute commands based on the input? (ex. GET BALL->how can I actually "get" the ball)

4. How can I allow users and objects within a game to interact? (This is probably getting into network programming which I would like to start learning)

Also, could someone analyze this code and tell me what I can do to make it more efficient or to make it easier for me to use?? If not, that is okay as it is 700+ lines long and quite a hefty job in my opinion...

#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>

using namespace std;

/*FUNCTION CALLS*/
void login_page();
void enter_game();
void create_character_name();
void create_character_password();
void create_character_gender();
void create_character_race();
void create_character_racechoose();
void create_character_verify();
void personal_info();
void help(string topic);
void exit_game();
void gameintro();
void game();
void score();
void dead();
void admin_achieve();

/*CONSTANTS*/
const int MAX_CLANS=10;//maximum number of clans a player can be in
const int SPEC_QUEST=10;//number of special quests(can be changed as needed)

/*VARIABLES*/
int choice;
int idnumber;
string name;
string password;
string proceedcc;
string createname;
string crnameyorn;
string createpassword;
string createpassword2;
string creategender;
string racechoose;
string racechooseyn;
string verifyyn;
string firstrealname;
string lastrealname;
string country;
int age;
string email;
string link;
string verifyyn2;
string race;
string gender;
string align;
string admin_ver;
string warcry;
string topic;
int explorers_level;
int level;
int max_health;
int current_health;
int strength;
int intelligence;
int dexterity;
int wisdom;
int devotion;
string guild;
string input;
string he_she;
string his_her;
int experience;
int lessons;
bool death;
bool from_main;

class Player
{
public:
string name;
string race;
string gender;//Male or Female
string alignment;//Angelic, Holy, Good, Neutral, Bad, Evil, Malicious
string admin_ver;//"is" or "isn't"
string clans[MAX_CLANS];//array holding clan names
string warcry;
string spec_quest[SPEC_QUEST];
int explorers_level;//number of unique rooms this character has visited
int level;//experience level
int max_health;//maximum health
int current_health;//current health
int strength;//strength stat
int intelligence;//intelligence stat
int dexterity;//dexterity stat
int wisdom;//wisom stat
int devotion;//devotion stat
string guild;
string password;
int experience;
int lessons;
};

/*USER DEFINES*/
//Mellonamin
Player Mellonamin;

//Elyon
Player Elyon;


int main()
{
cout<<"As a note, everything in the game is case-sensitive for the time being.\n";
cout<<" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
cout<<" | The Circle MUD |\n";
cout<<" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
cout<<" | / \n";
cout<<" / Your decisions determine your future--choose wisely. | \n";
cout<<" | / \n";
cout<<" / | \n";
cout<<" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n";
cout<<"\n\n\n";


Mellonamin.name="Mellonamin";
Mellonamin.race="Human";
Mellonamin.gender="Male";
Mellonamin.alignment="Neutral";
Mellonamin.admin_ver="isn't";
Mellonamin.warcry="For ELYON!";
Mellonamin.explorers_level=0;
Mellonamin.level=1;
Mellonamin.max_health=500;
Mellonamin.current_health=500;
Mellonamin.strength=10;
Mellonamin.intelligence=10;
Mellonamin.dexterity=10;
Mellonamin.wisdom=10;
Mellonamin.devotion=10;
Mellonamin.password="256772559";
Mellonamin.experience=0;
Mellonamin.lessons=125;

Elyon.name="Elyon";
Elyon.race="God";
Elyon.gender="Male";
Elyon.alignment="Angelic";
Elyon.admin_ver="is";
Elyon.warcry="Let it be!";
Elyon.explorers_level=1000;
Elyon.level=100;
Elyon.max_health=50000;
Elyon.current_health=50000;
Elyon.strength=15;
Elyon.intelligence=15;
Elyon.dexterity=15;
Elyon.wisdom=15;
Elyon.devotion=15;
Elyon.password="thecircle";
Elyon.experience=0;
Elyon.lessons=125;



login_page();
return 0;
}

void login_page()
{
cout<<" 1. Enter Game\n";
cout<<" 2. Create a New Character\n";
cout<<" 3. Help\n";
cout<<" 4. Exit Game\n";
cout<<"\n";
cout<<"Please choose an option above: ";
cin>>choice;
switch (choice)
{
case 1:
from_main=false;
enter_game();
break;
case 2:
from_main=false;
create_character_name();
break;
case 3:
from_main=true;
cout<<"Enter topic: ";
cin>>topic;
help(topic);
break;
case 4:
exit_game();
break;
default:
cout<<"Alas, that is not a choice.\n";
Sleep(2000);
login_page();
break;
}
}

void enter_game()
{
cout<<"Please input your character identification number: ";
cin>>idnumber;
switch (idnumber)
{
case 1:
{
name="Mellonamin";
cout<<"\nWelcome, "<<name<<"!";
cout<<"\nPlease input your password: ";
cin>>password;
if (password==Mellonamin.password)
{
Mellonamin.max_health=500;
Mellonamin.current_health=500;
cout<<"Password Verified...Proceeding to The Circle!\n";
Sleep(2000);
gameintro();
}
else
{
cout<<"Alas, that is not the password registered by that player.\n";
Sleep(3000);
enter_game();
}
}
break;
case 2:
{
name="Elyon";
cout<<"\nWelcome, "<<name<<"!";
cout<<"\nPlease input your password: ";
cin>>password;
if (password==Elyon.password)
{
cout<<"Password Verified...Proceeding to The Circle!\n";
Elyon.max_health=50000;
Elyon.current_health=49000;
Sleep(2000);
gameintro();
}
else
{
cout<<"Alas, that is not the password registered by that player.\n";
Sleep(3000);
enter_game();
}
}
break;
default:
{
cout<<"Alas, there is no character by that number.\n";
cout<<"Proceed to character creation process (y/n)? ";
cin>>proceedcc;
if (proceedcc=="y" || proceedcc=="Y")
{
create_character_name();
}
else
{
cout<<"Okay then.\n";
Sleep(2000);
main();
}
break;
}
}

}

void create_character_name()
{
cout<<"Enter a character name: ";
cin>>createname;
if (createname=="Mellonamin")
{
cout<<"Alas, the name you chose is already in use, please choose another.\n";
Sleep(2000);
create_character_name();
}
else
{
cout<<"Is "<<createname<<" the name you wish to use (y/n)? ";
cin>>crnameyorn;
if (crnameyorn=="Y" || crnameyorn=="y")
{
create_character_password();
}
else
{
cout<<"Okay then, choose another!\n";
Sleep(2000);
create_character_name();
}
}

}

void create_character_password()
{
cout<<"\nPlease input a password for your character (case sensitive): ";
cin>>createpassword;
cout<<"\nPlease input the same password for verification: ";
cin>>createpassword2;
if (createpassword==createpassword2)
{
create_character_gender();
}
else
{
cout<<"Alas, these passwords are not the same...\n";
Sleep(2000);
create_character_password();
}

}

void create_character_gender()
{
cout<<"\nWhat gender do you wish to be (m/f): ";
cin>>creategender;
if (creategender=="m"||creategender=="M")
{
cout<<"Welcome, Sir "<<createname<<"!\n";
create_character_race();
}
else if (creategender=="f"||creategender=="F")
{
cout<<"Welcome, Lady "<<createname<<"!\n";
create_character_race();
}
else
{
cout<<"Alas, that is not a valid gender.\n";
Sleep(2000);
create_character_gender();
}

}

void create_character_race()
{
bool done=false;
while (!done)
{
cout<<"Please choose a race: \n";
Sleep(1000);
cout<<"Human Elf Dwarf Roush\n";
cout<<"Turak-hai Jauga Horun Xellen\n";
cout<<"\n";
cout<<"For information on a specific race, type the race name as shown above\n";
cout<<"To choose a race, type DONE\n";
cout<<"::";
string raceinput;
raceinput="null";
cin>>raceinput;
if (raceinput=="Human" ||raceinput=="human"||raceinput=="HUMAN")
{
help("Human");
}
else if (raceinput=="Elf" || raceinput=="elf"||raceinput=="ELF")
{
help("Elf");
}
else if (raceinput=="Dwarf" || raceinput=="dwarf"||raceinput=="DWARF")
{
help("Dwarf");
}
else if (raceinput=="Roush" || raceinput=="roush"||raceinput=="ROSUH")
{
help("Roush");
}
else if (raceinput=="Turak-hai" || raceinput=="turak-hai"||raceinput=="TURAK-HAI")
{
help("Turak-hai");
}
else if (raceinput=="Jauga" || raceinput=="jauga"||raceinput=="JAUGA")
{
help("Jauga");
}
else if (raceinput=="Horun" || raceinput=="horun"||raceinput=="HORUN")
{
help("Horun");
}
else if (raceinput=="Xellen" || raceinput=="xellen"||raceinput=="XELLEN")
{
help("Xellen");
}
else if (raceinput=="DONE" || raceinput=="done" || raceinput=="Done")
{
done=true;
create_character_racechoose();
}
else
{
cout<<"That is not a valid race...\n";
Sleep(2000);
}
}
}

void create_character_racechoose()
{
cout<<"\nWhich race do you choose: ";
cin>>racechoose;
if (racechoose!="Human"&&racechoose!="human"&&racechoose!="HUMAN"&&racechoose!="Elf"&&racechoose!="elf"&&racechoose!="ELF"&&racechoose!="Dwarf"&&racechoose!="dwarf"&&racechoose!="DWAR F"&&racechoose!="Roush"&&racechoose!="roush"&&racechoose!="ROUSH"&&racechoose!="Turak-Hai"&&racechoose!="Turak-hai"&&racechoose!="TURAK-HAI"&&racechoose!="turak-hai"&&racechoose!=" turak-Hai"&&racechoose!="Jauga"&&racechoose!="jauga"&&racechoose!="JAUGA"&&racechoose!="Horun"&&racechoose!="horun"&&racechoose!="HORUN"&&racechoose!="Xellen"&&racechoose!="xellen" &&racechoose!="XELLEN")
{
cout<<"Alas, that is not a valid race!";
Sleep(2000);
create_character_racechoose();
}
else
{
cout<<"Is "<<racechoose<<" the race you wish to be (y/n)? ";
cin>>racechooseyn;
if (racechooseyn=="Y" || racechooseyn=="y")
{
create_character_verify();
}
else
{
create_character_racechoose();
}

}
}

void create_character_verify()
{
cout<<"\nName: "<<createname<<"\n";
cout<<"Password: "<<createpassword<<"\n";
cout<<"Gender: "<<creategender<<"\n";
cout<<"Race: "<<racechoose<<"\n";
cout<<"\nIs this information correct (y/n)? ";
cin>>verifyyn;
if (verifyyn=="Y" || verifyyn=="y")
{
personal_info();
}
else
{
cout<<"Proceeding to character creation...";
Sleep(2000);
create_character_name();
}

}

void personal_info()
{
cout<<"Please enter the following so we may contact you if need be. This information\nwill not be shared with any other parties.\n";
cout<<"Real First Name: ";
cin>>firstrealname;
cout<<"Real Last Name: ";
cin>>lastrealname;
cout<<"\nCountry of Residence (if name is more than one word, use abbreviation): ";
cin>>country;
cout<<"\nAge: ";
cin>>age;
cout<<"\nE-mail Address: ";
cin>>email;
cout<<"\nHow you found out about us (friend, Google, Link, etc.): ";
cin>>link;
cout<<"\n\nCharacter name: "<<createname;
cout<<"\nFirst Name: "<<firstrealname<<"\n";
cout<<"Last Name: "<<lastrealname<<"\n";
cout<<"Country: "<<country<<"\n";
cout<<"Age: "<<age<<"\n";
cout<<"E-mail: "<<email<<"\n";
cout<<"Source: "<<link<<"\n";
cout<<"Is this information correct (y/n)? ";
cin>>verifyyn2;
if (verifyyn2=="Y"||verifyyn2=="y")
{
ofstream file("players.pi", ios::app);
file<<"------------------------------------------------------\n";
file<<"Character Name: "<<createname;
file<<"\nFirst Name: "<<firstrealname<<"\n";
file<<"Last Name: "<<lastrealname<<"\n";
file<<"Country: "<<country<<"\n";
file<<"Age: "<<age<<"\n";
file<<"E-mail: "<<email<<"\n";
file<<"Source: "<<link<<"\n";
file.close();
cout<<"Thank you! You will be sent an email with details on how to enter the game.\nThis may take up to 24 hours. You will now be directed to The Circle.\n";
name=createname;
Sleep(5000);
gameintro();
}
else
{
personal_info();
}

}

void help(string topic)
{
cout<<"Searching help files for "<<topic<<"...\n";
Sleep(2000);
if (topic=="Human"||topic=="HUMAN"||topic=="human"||topic=="man"||topic=="Man"||topic=="humans"||topic=="Humans"||topic=="MAN"||topic=="HUMANS")
{
cout<<"\nHUMANS";
cout<<"\n\n\n\n\n\n";
cout<<"The Humans are the most basic of all the races as well as the most balanced.\n";
cout<<"Their natural habitats are in cities, but some have been known to live in the\n";
cout<<"wilderness, seeking to become closer to the things they love. They fare well\n";
cout<<"in all of the guilds, but some are better than others. The human race comes\n";
cout<<"from Tanis, the firstborn after the Great Deception.\n";
cout<<"\nStats--\n\n";
cout<<"Strength: 10\n";
cout<<"Intelligence: 10\n";
cout<<"Dexterity: 10\n";
cout<<"Wisdom: 10\n";
cout<<"Devotion: 10\n";
cout<<"\nBase Health: 500\n";
cout<<"\n\n--[Return] to continue--";
cin.get();
cin.get();
}
else if (topic=="Roush"||topic=="ROUSH"||topic=="roush")
{
cout<<"\nROUSH";
cout<<"\n\n\n\n\n\n";
cout<<"The Roush are a very unique race. They have the ability to fly that no other\n";
cout<<"race has. They look like 3 foot tall, white, furry bats. They live in the\n";
cout<<"villages of Terra Silvae, but can travel anywhere. The are excellent in the scout\n";
cout<<"and priest guilds due to their ability to fly and their excellent devotion and\n";
cout<<"wisdom. Although they are excellent in these two skills, they are lacking in the\n";
cout<<"others.\n";
cout<<"\nStats--\n\n";
cout<<"Strength: 7\n";
cout<<"Intelligence: 11\n";
cout<<"Dexterity: 8\n";
cout<<"Wisdom: 12\n";
cout<<"Devotion: 12\n";
cout<<"\nBase Health: 480\n";
cout<<"\n\n--[Return] to continue--";
cin.get();
cin.get();
}
else if (topic=="Elf"||topic=="elf"||topic=="ELF"||topic=="Elves"||topic=="elves"||topic=="ELVES")
{
cout<<"\nELVES";
cout<<"\n\n\n\n\n\n";
cout<<"The Elves are the creatures most closely tied to the forest. They may live in\n";
cout<<"any village, but their race hall is in a secret place in the forest. They tower\n";
cout<<"well over 6' tall upon reaching maturity. They have excellent vision, allowing\n";
cout<<"for their ability to be excellent in archery. Also because of their excellent \n";
cout<<"intelligence they make decent priests.\n";
cout<<"\nStats--\n\n";
cout<<"Strength: 8\n";
cout<<"Intelligence: 12\n";
cout<<"Dexterity: 12\n";
cout<<"Wisdom: 10\n";
cout<<"Devotion: 8\n";
cout<<"\nBase Health: 520\n";
cout<<"\n\n--[Return] to continue--";
cin.get();
cin.get();
}
else if (topic=="Dwarf"||topic=="dwarf"||topic=="DWARF"||topic=="Dwarves"||topic=="dwarves"||topic=="DWARVES")
{
cout<<"\nDWARVES";
cout<<"\n\n\n\n\n\n";
cout<<"The Dwarves are ground-dwelling creatures, but may also make their homes in\n";
cout<<"cities. They have excellent strength and health, making them good warriors.\n";
cout<<"They also have very tough skins giving them added defense. They are quite\n";
cout<<"short, but don'y let their size fool you, they are not creatures to mess with.\n";
cout<<"They have excellent night vision due to living in darkness. Dwarves also make\n";
cout<<"excellent forgers.\n";
cout<<"\nStats--\n\n";
cout<<"Strength: 12\n";
cout<<"Intelligence: 8\n";
cout<<"Dexterity: 9\n";
cout<<"Wisdom: 9\n";
cout<<"Devotion: 11\n";
cout<<"\nBase Health: 550\n";
cout<<"\n\n--[Return] to continue--";
cin.get();
cin.get();
}
if (from_main=true)
{
main();
}
}

void exit_game()
{
cout<<"Thanks for playing! Come back to Terra Silvae soon!\n";
Sleep(2000);
}

void gameintro()
{
cout<<"::Welcome back to Terra Silvae, "<<name<<"!\n";
if (idnumber==1)
{
race=Mellonamin.race;
gender=Mellonamin.gender;
align=Mellonamin.alignment;
admin_ver=Mellonamin.admin_ver;
warcry=Mellonamin.warcry;
explorers_level=Mellonamin.explorers_level;
level=Mellonamin.level;
max_health=Mellonamin.max_health;
current_health=Mellonamin.current_health;
strength=Mellonamin.strength;
intelligence=Mellonamin.intelligence;
dexterity=Mellonamin.dexterity;
wisdom=Mellonamin.wisdom;
devotion=Mellonamin.devotion;
guild=Mellonamin.guild;
experience=Mellonamin.experience;
lessons=Mellonamin.lessons;
}
else if (idnumber==2)
{
race=Elyon.race;
gender=Elyon.gender;
align=Elyon.alignment;
admin_ver=Elyon.admin_ver;
warcry=Elyon.warcry;
explorers_level=Elyon.explorers_level;
level=Elyon.level;
max_health=Elyon.max_health;
current_health=Elyon.current_health;
strength=Elyon.strength;
intelligence=Elyon.intelligence;
dexterity=Elyon.dexterity;
wisdom=Elyon.wisdom;
devotion=Elyon.devotion;
lessons=Elyon.lessons;
experience=Elyon.experience;
}
Sleep(2000);
game();
}

void game()
{
if (gender=="Male"||gender=="male")
{
he_she="He";
his_her="His";
}
else
{
he_she="She";
his_her="Her";
}
while (death!=true)
{
if (experience>=100)
{
experience=0;
max_health=max_health+50;
current_health=current_health+50;
level++;
if (level==10)
{
lessons=lessons+10;
}
else if(level==20)
{
lessons=lessons+15;
}
else if(level==30)
{
lessons=lessons+20;
}
else if(level==40)
{
lessons=lessons+25;
}
else if(level==50)
{
lessons=lessons+30;
}
else if (level==60)
{
lessons=lessons+35;
}
else if (level==70)
{
lessons=lessons+40;
}
else if (level==80)
{
lessons=lessons+45;
}
else if(level==90)
{
lessons=lessons=55;
}
else if (level==99)
{
lessons=lessons+70;
}
else if (level==100)
{
admin_achieve();
}
else
{
lessons=lessons+5;
}
}

cout<<"::["<<current_health<<"/"<<max_health<<"]::";
cin>>input;
if (input=="SCORE"||input=="score"||input=="Score")
{
score();
}
}
dead();
}

void score()
{
cout<<"::Score for "<<name<<":\n";
cout<<"Your experience level is at "<<experience<<"%.\n";
cout<<"You have "<<lessons<<" lessons.\n";
cout<<"You are "<<race<<".\n";
cout<<"You are "<<align<<".\n";
cout<<"Your warcry is: "<<warcry<<".\n";
cout<<"Your explorers level is: "<<explorers_level<<".\n";
system("Pause");
}

void dead()
{
cout<<"::["<<current_health<<"/"<<max_health<<"]::You gasp as your last breath leaves your body.\n";
Sleep(4000);
cout<<"::["<<current_health<<"/"<<max_health<<"]::Everything around you goes dim.\n";
Sleep(4000);
cout<<"::["<<current_health<<"/"<<max_health<<"]::'"<<name<<", you have been overtaken by worldly destruction,' you\n::["<<current_health<<"/"<<max_health<<"]::hear a booming voice say.\n";
Sleep(6000);
cout<<"::["<<current_health<<"/"<<max_health<<"]::'You have not yet fulfilled your destiny in the grand plot, so\n::["<<current_health<<"/"<<max_health<<"]::you will be returned to Terra Silvae,' the booming voice says kindly.\n";
Sleep(6000);
cout<<"::["<<current_health<<"/"<<max_health<<"]::'Remember, "<<name<<" there is always help when you need it.\n::["<<current_health<<"/"<<max_health<<"]::Always remember that...'\n";
Sleep(5000);
cout<<"::["<<current_health<<"/"<<max_health<<"]::Your senses are awakened as you realize you have been returned\n::["<<current_health<<"/"<<max_health<<"]::to Terra Silva.\n";
Sleep(4000);
game();
}

void admin_achieve()
{
cout<<"Congratulations, "<<name<<" you have officially reached the level eligibility\nrequirement to become an administrator of The Circle MUD. You will be contacted\nin a few days!\n";
Sleep(15000);
ofstream file2("adminAchieve.aa", ios::app);
file2<<"------------------------------------------\n";
file2<<name;
file2.close();
}

Thanks everyone!!!

------------------
Vita sine Ieso est mors.
Life without Jesus is death.

HanClinto

Administrator

Posts: 1828
From: Indiana
Registered: 10-11-2004
Phew, lots of questions. Thanks for itemizing them, I'll do my best to answer some of them.


quote:
Originally posted by mellonamin:
1. How can I convert a string of text to all uppercase or all lowercase?


I believe it's ucase(string) or myString.UCase().

quote:
Originally posted by mellonamin:
2. How can I split my source code for a game up into different files and still use functions from each of them in any file? Right now I have like 25 different functions within about 700 lines of file and it is getting kind of confusing...


Put them into different .cpp or .hpp files and use #include "thisfile.cpp" or #include "thatfile.hpp". So for instance, here's your original file:
quote:

#include <iostream>

using namespace std;

void main (void)
{
... blah ...
ThisFunction();
... blah ...
ThatFunction();
... blah ...
}

void ThisFunction(void)
{
... blah ...
}

void ThatFunction(void)
{
... blah ...
}


Well you can split that up like so:

quote:

/* main.cpp */
#include <iostream>
#include "thisfile.cpp"
#include "thatfile.cpp"

using namespace std;

void main(void)
{
... blah ...
ThisFunction();
... blah ...
ThatFunction();
... blah ...
}



quote:

/*thisfile.cpp*/
#include <iostream>

using namespace std;

void ThisFunction(void)
{
... blah ...
}



quote:

/*thatfile.cpp*/
#include <iostream>

using namespace std;

void ThatFunction(void)
{
... blah ...
}


I hope that makes sense.

quote:
Originally posted by mellonamin:
3. How can I get multi-word strings from a user and then execute commands based on the input? (ex. GET BALL->how can I actually "get" the ball)


I think there's a "split" function or something like that, though I'm not sure.

quote:
Originally posted by mellonamin:
4. How can I allow users and objects within a game to interact? (This is probably getting into network programming which I would like to start learning)


Yup! That's exactly what this is. You may want to go to PlanetSourceCode.com and download a C chat program example, that will give you a really good start on this and show you some stuff much better than I can recall from memory here.

quote:
Originally posted by mellonamin:
Also, could someone analyze this code and tell me what I can do to make it more efficient or to make it easier for me to use?? If not, that is okay as it is 700+ lines long and quite a hefty job in my opinion...


Not gonna' do that for you right now, sorry.

Hope that helps!

Respectfully,
clint

------------------
http://www.includingjudas.com/christiangame.html

mellonamin

Member

Posts: 119
From: Maryville, TN, United States
Registered: 11-16-2004
heh, thanks for your help clinto! I didn't expect anyone to do the code thing right now anyway

------------------
Vita sine Ieso est mors.
Life without Jesus is death.

Briant

Member

Posts: 742
From: Stony Plain, Alberta, Canada
Registered: 01-20-2001
To add to what HanClinto said, it's generally not good practice to #include any .cpp files. In general, declarations and code goes in .cpp files, definitions, defines, etc. go in header files. It will save you a ton of grief later.

About your 700 lines of code, here's some general tips (organization is crucial!):

- avoid all those global variables. Sort/group them, and put them inside structure or even classes.
- create some look-up tables for your races, like this:


struct RaceDefinition
{
string race;
string description;
int strength;
int intelligence;
int dexterity;
int wisdom;
int devotion;
int basehealth;
}

Then you could define your races like this:


struct Races[] = {
{ "ELVES",
"The Elves are the creatures most closely tied to the forest. They may live in\nany village, but their race hall is in a secret place in the forest. They tower\nwell over 6' tall upon reaching maturity. They have excellent vision, allowing\nfor their ability to be excellent in archery. Also because of their excellent \nintelligence they make decent priests.\n",
8, 12, 12, 10, 8, 520 },
{ "DWARVES",
"The Dwarves are ground-dwelling creatures, but may also make their homes in\ncities. They have excellent strength and health, making them good warriors.\nThey also have very tough skins giving them added defense. They are quite\nshort, but don'y let their size fool you, they are not creatures to mess with.\nThey have excellent night vision due to living in darkness. Dwarves also make\nexcellent forgers.\n",
12, 8, 9, 9, 11, 550 },
// and so on
};

That's just some starter suggestions.

------------------
Brian

HeardTheWord

Member

Posts: 224
From: Des Moines, IA
Registered: 08-16-2004
I am all about the object oriented programming side of C++. Inheiritance
is something you should look into. You can create a base class that all
races are formed from and then create subclasses that represent each race.

I had a teacher that wouldn't allow us to use global variables. Most
people hated him until they found out that their skill improved. Passing
variables around and still saving space takes more thought but in the
long run it will pay off. Like BrianT said, Organization is the key.

[This message has been edited by HeardTheWord (edited January 04, 2005).]

CobraA1

Member

Posts: 926
From: MN
Registered: 02-19-2001
woah - Yeah, learn some Object Oriented programming. Avoid global variables and functions. Learn how to use inheritance instead.

Once you learn that, you'll learn how to use general objects (base class) to provide a larger framework for more specialized objects (subclasses) to avoid code replication. A more specialized object can always overload functions it needs to be different, and it will inherit common code that all objects of its type need.

Once you have everything done in an Object Oriented manner, try to put each class into its own file. That's the way Java programmers do it, and it seems to be a reasonable way of doing things.

------------------
"The very idea of freedom presupposes some objective moral law which overarches rulers and ruled alike." -- C. S. Lewis (1898 - 1963), "The Poison of Subjectivism" (from Christian Reflections; p. 108)

Switch Mayhem now available! Get it here
Codename: Roler - hoping to get more done over the holidays . . .

ArchAngel

Member

Posts: 3450
From: SV, CA, USA
Registered: 01-29-2002
ever since my Java class, I'm big into OOP.
love it.
even though I'm kinda a newbie.

------------------
Soterion Studios

mellonamin

Member

Posts: 119
From: Maryville, TN, United States
Registered: 11-16-2004
Would any of you reccomend changing my "string" objects to C-style strings? I found out that if I do that, I can use this function to convert the characters to uppercase quite easily...

#include <iostream>
#include <string>
#include <string.h>
#include <windows.h>
#include <stdio.h>


using namespace std;

int main()
{
cout<<"Enter string: ";
char string1[100];
cin>>string1;
strupr(string1);
cout<<string1;
cin.get();
cin.get();
}

------------------
Vita sine Ieso est mors.
Life without Jesus is death.

Briant

Member

Posts: 742
From: Stony Plain, Alberta, Canada
Registered: 01-20-2001
quote:
Originally posted by mellonamin:
Would any of you reccomend changing my "string" objects to C-style strings? I found out that if I do that, I can use this function to convert the characters to uppercase quite easily...

You could do that, sure. Alternatively, you could derive your own string class from std::string, and add a ToUpper member function yourself. Are you familiar with C++ enough to do this yourself, or would you like some example code?

------------------
Brian