Hello, I'm new to the community and pretty new to C++. Well, I learned some C++ in high school about 6 years ago, but nothing beyond the basics. Lately I decided to pick up C++ again and actually learn the language beyond the basics, and that way I can try and design my own little games and other projects.
Anyway, I decided that my first project would be a small console game, which should force me to learn some of the core concepts of C++ and OOP. I've done some of the coding already and learned quite a bit. However, I have 2 questions I haven't been able to find clear answers out there, after finding so many of my answers in this forum I figured I would start by asking here.
-->> 1 -->> I Plan on having characters in my game, probably between 50-100 or them. I would like to have these characters with different sets of profiles (which would be made up of strings, integers and other variables) and ideally I'd like to have these profiles change over time. From my understanding right now, I decided a good way to go would be to declare a class (class cToons) that defines what all characters will have such as name, stamina, intelligence, etc. From there I would be able to instantiate my 50-100 characters so that each one is saved as an object. This seems to be the logical way to do it for me as a noobie.
Now, my first problem was that I didn't want to write these 100 instantiations in my main() function. My first idea was to actually write all these instantiations in a whole separated source file (characters.cpp), which would then be linked to my main.cpp via a characters.h header file. Well after trying that and realizing having this in a separate .cpp would be a lot harder, I thought about doing the instantiations in the header file itself. That didn't work either. Finally, I gave up and moved the instantiations to my main.cpp file, but I thought it may be useful if I could write all this code outside of my main() function. Even better, I thought it would be a good idea to do this in a function (fnToons()) outside of main() and then I would use that functions only once at the beginning of the game to create all the characters. Well, I tried that as well and it didn't work, let me show more detail on what I did:
This is the function for instantiating my character objects, in this case I only have 1 character but it shouldn't matter for now.
###########################################
int main()
{
//Resizes the console window
int height = 50;
int width = 100;
Console::SetWindowSize( width, height );
//variable used to stop the program
char vMenuSel;
bool vEndGame = false;
fnToons();
while (vEndGame == false)
{
system("cls"); //clears console
cout << con::fg_yellow << "Project ERSTE v0.1";
cPrint qGame;
qGame.PrintBoard();
//Display area
switch (vMenuSel)
{
case 'a':
{
cout << con::fg_green << "\n-------------------------------Personel Screen-------------------------------";
cout << con::fg_white << "\n\n Character Ability Salary Assignment Location Heat"<< endl;
// unsigned short outStamina = toon01.getStamina();
// cout << "Stamina value is " << outStamina << endl;
break;
}
case 'Z':
{
vEndGame = true;
cout << con::fg_red << "\n You will now exit the game\n Goodbye" << con::fg_black;
break;
}
default:
{
break;
}
}
//Menu selection entry
cout << "\nEnter your next action and press" << con::fg_green << " ENTER" <<endl;
cin >> vMenuSel;
cout << "you typed the letter" << vMenuSel << "\n";
Console::ReadKey( true );
}
return 0;
}
##########################################
Now when I change this, and swap my fnToons(); for the actual instantiations, it works. Basically anytime I instantiate my character objects in main() I get no errors, but as soon as I change so that is done through a function, it gives me errors. Any suggestions????
-->> 2 -->> Now my second question... If I create all these characters and start playing my game, what are my options in terms of saving my game so I can play some other time? I was thinking of using input/output streams and just writing all the characters' information in a text file that I would be able to retrieve later using another function instead of fnToons(), which would instantiate all my characters and stuff using the information on that .txt file or whatever. I am fairly certain there are better ways of doing this, any suggestions???