(main.cpp)
/*They must have save.txt in same directory as game.exe*/
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;
/*Forward Declarations*/
int nTest();
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip);
/*Global Stats*/
int nStr=-1;
int nHealth=-1;
int nMana=-1;
int nDefense=-1;
int nLevel=-1;
int nXP=0;
string sName="-1";
string sGender="-1";
string sOrder="-1";
/*Monsters*/
//Tutorial Monster
string sTutName="Tutorial Monster";
int nTutStr=1;
int nTutHealth=8;
int nTutMana=10;
int nTutDefense=1;
string sTutDescrip="A monster used by the game to teach the player how combat works. ";
//TODO: More monsters
int main () {
srand(time(NULL)); //seeds the time ONCE (ty Oler1s)
int nCounter=0; //starts the counter for 'for' loops
int nStartR=1;
int nInput;
int genderLoop=1;
int orderLoop=1;
int statLoop=1;
int skipTut=1;
int tutLoop;
int F=-1; //TODO: Replace with the last level
while (nStartR) {
cout << "Hello! What would you like to do? " << endl;
cout << "1. Load Game" << endl;
cout << "2. New Game (will erase any saved data)" << endl;
cin >> nInput;
system("cls");
switch(nInput) {
case 1: {
nLoad(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
cout << "Name: " << sName << endl;
cout << "Gender: " << sGender << endl;
cout << "Order: " << sOrder << endl;
cout << "Strength: " << nStr << endl;
cout << "Health: " << nHealth << endl;
cout << "Mana: " << nMana << endl;
cout << "Defense: " << nDefense << endl;
cout << "Level: " << nLevel;
nStartR=0;
break;
}
case 2: {
cout << "Starting a new game..." << endl;
nLevel=1;
cout << "Hello! Welcome to the game! " << endl;
cout << "What is your first name? \n" << endl;
cin.ignore(); //http://www.cplusplus.com/forum/beginner/5649/ <- Thanks
getline(cin,sName);
nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
while (genderLoop) {
cout << "Are you a: " << endl;
cout << "1. Boy" << endl;
cout << "2. Girl" << endl;
cin.clear();
cin >> nInput;
switch(nInput) {
case 1: {
sGender="Boy";
genderLoop=0;
break;
}
case 2: {
sGender="Girl";
genderLoop=0;
break;
}
default: {
cout << "Error in input. Going back";
cin.clear();
}
} //ends switch
nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
} //ends genderLoop
system("cls");
cin.clear();
while(orderLoop) {
cout << "When you were a kid, did you like to: " << endl;
cout << "1. Be sneaky and steal things from people. " << endl;
cout << "2. Be up front and personal when there was a conflict at hand. " << endl;
cout << "3. Be in the back reading books and studying. " << endl;
cin >> nInput;
switch(nInput) {
case 1: {
sOrder="Rogue";
cout << "A sneaky, lying Rogue. \nYou lie and cheat and scam other people to make ends meet. " << endl;
cout << "Rogues tend to have more Defense as they're used to hiding and dodging. " << endl;
cout << "They also have lower Health as they aren't used to taking hits. " << endl;
cout << "They've never conditioned themselves to be able to take many hits. " << endl;
cout << "They also have weaker hits because they've always striken in the dark. " << endl;
orderLoop=0;
system("PAUSE");
break;
}
case 2: {
sOrder="Warrior";
cout << "A powerful warrior who uses a broad sword and is not afraid of a challenge. " << endl;
cout << "Warriors tend to have higher Strength and Life. " << endl;
cout << "Unfortunately, due to their recklessness, they never studied magic or cared about safety. " << endl;
cout << "This leads to an inability to use Magic and lower Defense. " << endl;
orderLoop=0;
system("PAUSE");
break;
}
case 3: {
sOrder="Mage";
cout << "Your entire life you've spent reading and studying the arcane magics. " << endl;
cout << "You've learned spells and how to maximize your Mana reserves. " << endl;
cout << "Due to your lack of physical training, you have very low Strength and Health. " << endl;
orderLoop=0;
system("PAUSE");
break;
}
default: {
cout << "Unknown option, restarting. ";
system("cls");
}
} //ends switch statement
} //ends orderLoop
nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
while(statLoop) { //Assigns values based on the order they picked
/*Base Health = 20, Base Mana = 20, Base Strength and Defense = 5*/
if (sOrder=="Rogue") {
nHealth=15;
nMana=20;
nStr=3;
nDefense=7;
statLoop=0;
}
else if (sOrder=="Warrior") {
nHealth=25;
nMana=0;
nStr=8;
nDefense=2;
statLoop=0;
}
else if (sOrder=="Mage") {
nHealth=15;
nMana=35;
nStr=1;
nDefense=2;
statLoop=0;
}
else
cout << "Error @ statLoop";
} //ends statLoop
nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
nStartR=0;
break;
} //ends case 2
default: {
cout << "Unknown option. Restarting..." << endl;
system("cls");
}
} //ends first switch
} //ends first while loop
while (nLevel!=F){
switch(nLevel) {
case 1: {
system("cls");
while (skipTut) {
cout << "Welcome to the game! " << endl;
cout << "This is just a tutorial to learn the battle system. " << endl;
cout << "Do you want to skip it? " << endl;
cout << "1. Yes" << endl;
cout << "2. No" << endl;
cin.clear();
cin >> tutLoop;
switch(tutLoop) {
case 1: {
skipTut=0;
nLevel++;
break;
}
case 2: {
skipTut=0;
break;
}
default: {
cout << "Unknown option. Restarting...";
system("cls");
cin.clear();
}
} //ends switch
} //ends skipTut Loop
system("cls");
cin.clear();
cout << "Welcome to the tutorial. " << endl;
cout << "Here you will be placed in combat with a small monster to learn how things work. " << endl;
cout << "Press Enter to go into the fight. \n";
system("PAUSE");
int nCombatTut(string sName, string sGender, string sOrder, int nStr, int nHealth, int nMana, int nDefense, int nXP, string sTutName, int nTutStr, int nTutHealth, int nTutMana, int nTutDefense, string sTutDescrip);
//COMPARING:int nCombatTut(string &pName, string &pGender, string &pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip);
//TODO: Insert tutorial combat function
nLevel++;
nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
break;
}
case 2: {
cout << "Welcome to level 2!" << endl;
system("PAUSE");
nLevel++;
break;
}
default: {
cout << "Error at Levels switch. " << endl;
system("PAUSE");
nLevel++;
break;
}
} //ends Levels switch
} //ends while loop
system("PAUSE");
return 0;
}
(functions.cpp)
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;
int nTest() { //Random number out of 10
cout << rand() % 10 + 1 << endl;
return 0;
}
/*Saving function*/
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
ofstream saveFile ("save.txt", ios::in | ios::out, ios::trunc);
saveFile
<< Name << "\n"
<< Gender << "\n"
<< Order << "\n"
<< Strength << "\n"
<< Health << "\n"
<< Mana << "\n"
<< Defense << "\n"
<< Level << "\n"
<< XP << "\n";
saveFile.close();
return 0;
}
/*Loading function*/
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
fstream loadFile ("save.txt", ios::in | ios::out);
loadFile >> Name;
loadFile >> Gender;
loadFile >> Order;
loadFile >> Strength;
loadFile >> Health;
loadFile >> Mana;
loadFile >> Defense;
loadFile >> Level;
loadFile >> XP;
loadFile.close();
return 0;
}
/*Combat function*/
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip) {
int nMenu;
cout << "Welcome to the tutorial, " << pName << endl;
cout << "Tutorial Monster: \"You have to beat me to finish this tutorial! \"" << endl;
cout << "Just pick the options to go throughout the fight. " << endl;
cout << "1. Status (Check status of fight)" << endl;
system("PAUSE");
return 0;
}
These are the errors:
Quote
1>c:\users\cyrus\documents\visual studio 2010\projects\game\main.cpp(224): error C2440: 'initializing' : cannot convert from 'std::string' to 'int'
Line 224 of main.cpp should be calling the Combat Tutorial function, but it isn't. I'm getting no errors and I don't see why it's just skipping over the function.
I've counted all 3 functions (well: the actual function in functions.cpp, the forward declaration and the actual call in main) so many times the words are literally swirling around(like seriously, I had to go take a break before I typed this up). I've gotten 14 arguments each time.
In addition to this, error C2440 doesn't make sense to me. I looked it up and it says it happens when you try to convert two things that can't be converted or when I try to convert a pointer to a member to a class. I didn't know what a member was so I looked it up and got:
Quote
and I didn't know what a class was so I looked it up and I know I haven't declared any now.
The other things that it mentions in the MSDN article where things like Arrays or assigning 0 to pointers, things I'm not doing.
What am I doing wrong?
This post has been edited by Cyrusthebeast: 06 June 2010 - 07:50 PM

New Topic/Question
Reply




MultiQuote







|