Im sorry if my game code is long, but, the save feature wont work. Their are no errors, but when I load the game and buy weapons the stats are correct, but when I save and load It the stats are not there. Can you please help me? Yes I have not finished mission 1 - 5 yet.
#include<iostream.h>
#include<fstream>
#include<string>
using namespace std;
char choice;
int missionNumber = 0;
int smissionNumber;
int gamsoldiers = 25;
int ricsoldiers = 25;
int galsoldiers = 25;
int salsoldiers = 25;
int amesoldiers = 25;
void mission1();
void mission2();
void mission3();
void mission4();
void mission5();
void newGame();
void loadGame();
void saveGame();
void statScreen();
int battleScreen();
void rHenchmen();
void weaponBuy();
void kMafia();
void enemyPeople();
void gambino();
void ricci();
void gallo();
void salvatore();
void american();
//Player********
string pName;
int respect = 0;
int strength = 0;
string weapons[10] = "none";
int pammo = 0;
int paccuracy = 20;
int uziammo = 0;
int uziaccuracy = 10;
int sgammo = 0;
int sgaccuracy = 5;
int arammo = 0;
int araccuracy = 50;
int srammo = 0;
int sraccuracy = 90;
int agility;
int money;
int health = 100;
int barmor = 100;
string filename;
//**************
//SVAES***************************
int sstrength;
int srespect;
int spammo;
int suziammo;
int ssgammo;
int sarammo;
int ssrammo;
int sagility;
int smoney;
int sbarmor;
int shealth;
int sgamsoldiers;
string a;
char a1;
//********************************
void ricci()
{
system("CLS");
cout << endl << "\tDon - Michael Ricci" << endl << endl;
cout << "\tRight Hand Man - Antonio Gallo" << endl << endl;
cout << "\tLeft Hand Man - ~~~~~~~~~~~~~~~" << endl << endl;
cout << "\t" << ricsoldiers << " Soldiers" << endl << endl;
system("PAUSE");
enemyPeople();
return;
}
void gallo()
{
system("CLS");
cout << endl << "\tDon - Alfredo Gallo" << endl << endl;
cout << "\tRight Hand Man - ~~~~~~~~~~~~~~" << endl << endl;
cout << "\tLeft Hand Man - ~~~~~~~~~~~~~~~~~" << endl << endl;
cout << "\t" << galsoldiers << " Soldiers" << endl << endl;
system("PAUSE");
enemyPeople();
return;
}
void salvatore()
{
system("CLS");
cout << endl << "\tDon - Antonio Salvetore" << endl << endl;
cout << "\tRight Hand Man - ~~~~~~~~~~~~~~~" << endl << endl;
cout << "\tLeft Hand Man - ~~~~~~~~~~~~~~~~~" << endl << endl;
cout << "\t" << salsoldiers << " Soldiers" << endl << endl;
system("PAUSE");
enemyPeople();
return;
}
void american()
{
system("CLS");
cout << endl << "\tDon - Tom Johnson" << endl << endl;
cout << "\tRight Hand Man - ~~~~~~~~~~~~~~~~~" << endl << endl;
cout << "\tLeft Hand Man - ~~~~~~~~~~~~~~~~~~~~~~" << endl << endl;
cout << "\t" << amesoldiers << " Soldiers" << endl << endl;
system("PAUSE");
enemyPeople();
return;
}
void gambino()
{
system("CLS");
cout << endl << "\tDon - Lou Gambino" << endl << endl;
cout << "\tRight Hand Man - Hank Rico" << endl << endl;
cout << "\tLeft Hand Man - Benito Deluca" << endl << endl;
cout << "\t" << gamsoldiers << " Soldiers" << endl << endl;
system("PAUSE");
enemyPeople();
return;
}
void saveGame()
{
cout << "What do you want your filename to be?" << endl;
cin >> filename;
ofstream gamefile;
gamefile.open(filename.c_str());
gamefile << smissionNumber;
missionNumber = smissionNumber;
gamefile << sstrength;
strength = sstrength;
gamefile << srespect;
respect = srespect;
gamefile << spammo;
pammo = spammo;
gamefile << suziammo;
uziammo = suziammo;
gamefile << ssgammo;
sgammo = ssgammo;
gamefile << sarammo;
arammo = sarammo;
gamefile << ssrammo;
srammo = ssrammo;
gamefile << sagility;
agility = sagility;
gamefile << smoney;
money = smoney;
gamefile << sbarmor;
barmor = sbarmor;
gamefile << srespect;
respect = srespect;
gamefile << shealth;
health = shealth;
gamefile << sgamsoldiers;
gamsoldiers = sgamsoldiers;
gamefile.close();
battleScreen();
return;
}
void enemyPeople()
{
system("CLS");
cout << "1.Gambino Family" << endl << endl;
cout << "2.Ricci Family" << endl << endl;
cout << "3.Gallo Family" << endl << endl;
cout << "4.Salvatore Family" << endl << endl;
cout << "5.American Mafia" << endl << endl;
cout << "6.Back" << endl << endl;
cin >> a1;
switch (a1)
{
case '1':
gambino();
case '2':
ricci();
case '3':
gallo();
case '4':
salvatore();
case '5':
american();
case '6':
battleScreen();
}
return;
}
void kMafia()
{
return;
}
void weaponBuy()
{
cout << "1.Pistol(50) $200" << endl;
cout << "2.Uzi(300) $500" << endl;
cout << "3.Shotgun(10) $600" << endl;
cout << "4.Assult Rifle(500) $1000" << endl;
cout << "5.Sniper Rifle(10) $1500" << endl;
cout << "6.Body Armor(1) $200" << endl;
cout << "7.Back" << endl;
cin >> a1;
switch (a1)
{
case '1':
if (money >= 200)
{
system("CLS");
cout << "Pistol Bought" << endl;
pammo = pammo + 50;
money = money - 200;
system("PAUSE");
weaponBuy();
}
else
{
cout << "You need at least $200" << endl;
system("PAUSE");
weaponBuy();
}
case '2':
if (money >= 500)
{
system("CLS");
cout << "Uzi Bought" << endl;
uziammo = uziammo + 300;
money = money - 500;
system("PAUSE");
weaponBuy();
}
else
{
cout << "You need at least $500" << endl;
system("PAUSE");
weaponBuy();
}
case '3':
if (money >= 600)
{
system("CLS");
cout << "Shotgun Bought" << endl;
sgammo = sgammo + 50;
money = money - 200;
system("PAUSE");
weaponBuy();
}
else
{
cout << "You need at least $600" << endl;
system("PAUSE");
weaponBuy();
}
case '4':
if (money >= 1000)
{
system("CLS");
cout << "Assult Rifle Bought" << endl;
arammo = arammo + 500;
money = money - 1000;
system("PAUSE");
weaponBuy();
}
else
{
cout << "You need at least $1000" << endl;
system("PAUSE");
weaponBuy();
}
case '5':
if (money >= 1500)
{
system("CLS");
cout << "Sniper Rifle Bought" << endl;
srammo = srammo + 10;
money = money - 1500;
system("PAUSE");
weaponBuy();
}
else
{
cout << "You need at least $1500" << endl;
system("PAUSE");
weaponBuy();
}
case '6':
if (money >= 200)
{
system("CLS");
cout << "Body Armor Bought" << endl;
barmor = 100;
money = money - 200;
system("PAUSE");
weaponBuy();
}
else
{
cout << "You need at least $200" << endl;
system("PAUSE");
weaponBuy();
}
case '7':
battleScreen();
}
return;
}
void mission1()
{
return;
}
void mission2()
{
return;
}
void mission3()
{
return;
}
void mission4()
{
return;
}
void mission5()
{
return;
}
void statScreen()
{
system("CLS");
cout << "\tRespect: " << respect << endl << endl;
cout << "\tStrength: " << strength << endl << endl;
cout << "\tWeapons & Ammo:" << endl << endl << "Baseball Bat" << endl << endl << "Pistol: " << pammo << endl << endl << "Uzi: " << uziammo << endl << endl << "Shotgun: " << sgammo << endl << endl;
cout << "Assult Rifle: " << arammo << endl << endl << "Sniper Rifle: " << srammo << " \t\t\tScroll Up and Down" << endl << endl;
cout << "\tWeapon Accuracy:" << endl << endl << "Pistol(" << paccuracy << "%)" << endl << endl << " Uzi(" << uziaccuracy << "%)" << endl << endl << " Shotgun(" << sgaccuracy << "%)" << endl << endl;
cout << " Assult Rifle(" << araccuracy << "%)" << endl << endl << " Sniper Rifle(" << sraccuracy << "%)" << endl << endl << endl;
cout << "\tMission " << missionNumber << "/5" << endl << endl;
cout << "\tMoney: $" << money << endl << endl;
cout << "\tHealth: " << health << endl << endl;
cout << "\tBody Armor: " << barmor << endl << endl;
system("PAUSE");
battleScreen();
return;
}
int battleScreen()
{
system("CLS");
money = 200;
cout << "Gambino: By the way, kid, heres a baseball bat, and body armor.";
cout << endl << endl << endl;
cout << "\t1.Save Game" << endl;
cout << "\t2.Continue Missions " << missionNumber << "/5" << endl;
cout << "\t3.Check Stats" << endl;
cout << "\t4.Buy Weapons" << endl;
cout << "\t5.Kill Mafia" << endl;
cout << "\t6.Enemy Gang People" << endl;
cin >> choice;
switch (choice)
{
case '1':
saveGame();
case '2':
switch (missionNumber)
{
case 1:
mission1();
case 2:
mission2();
case 3:
mission3();
case 4:
mission4();
case 5:
mission5();
}
case '3':
statScreen();
case '4':
weaponBuy();
case '5':
if (respect != 100)
{
system("CLS");
cout << "Sorry, you have to be 100 respect to use this feature" << endl;
system("PAUSE");
battleScreen();
}
else
{
kMafia();
}
case '6':
enemyPeople();
}
return 0;
}
void newGame()
{
//Intro
system("CLS");
cout << "You are walking home from school..." << endl << endl;
system("PAUSE");
cout << endl;
cout << "BAM!! You and your books fall to the floor" << endl << endl;
system("PAUSE");
system("CLS");
cout << "Punk1: Thats what you get for messin' with the Gallo Family." << endl << endl;
cout << "The punks run but..." << endl << endl;
cout << "WHACK!! An unknown person hits the punks with a baseball bat." << endl << endl;
system("PAUSE");
system("CLS");
cout << "The unknown person is walking slowly towards you..." << endl << endl;
system("PAUSE");
cout << endl;
cout << "Unknown Person: Are you okay?" << endl << endl;
cout << "You: Yea I'm okay." << endl << endl;
cout << "Gambino: Good. My name is Don Gambino. Whats yours?" << endl;
cin >> pName;
cout << "Gambino: Nice to meet you " << pName << endl << endl;
cout << "Gambino: Would ya do to those guys?" << endl << endl;
cout << "You: Umm... I... hit them." << endl << endl;
cout << "Gambino: Oh. I see. How wold you like to get some revenge on those guys?" << endl << endl;
cout << "You: Sure!" << endl << endl;
cout << "Gambino: Come with me." << endl << endl;
system("PAUSE");
battleScreen();
return;
}
void loadGame()
{
cout << "What was your filename?" << endl;
cin >> filename;
ifstream gamefile;
gamefile.open(filename.c_str());
if (!gamefile)
{
cout << "Invalid name please enter again" << endl;
system("PAUSE");
loadGame();
}
gamefile >> missionNumber;
smissionNumber = missionNumber;
gamefile >> strength;
sstrength = strength;
gamefile >> respect;
srespect = respect;
gamefile >> pammo;
spammo = pammo;
gamefile >> uziammo;
suziammo = uziammo;
gamefile >> sgammo;
ssgammo = sgammo;
gamefile >> arammo;
sarammo = arammo;
gamefile >> srammo;
ssrammo = srammo;
gamefile >> agility;
sagility = agility;
gamefile >> money;
smoney = money;
gamefile >> barmor;
sbarmor = barmor;
gamefile >> respect;
srespect = respect;
gamefile >> gamsoldiers;
sgamsoldiers = gamsoldiers;
gamefile.close();
battleScreen();
return;
}
main()
{
cout << " -----------------------------------------------------------------" << endl;
cout << " | Welcome To |" << endl;
cout << " | |" << endl;
cout << " | |" << endl;
cout << " | The Mafia Game |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------------------------------------" << endl << endl << endl << endl;
cout << "\t1.New Game" << endl;
cout << "\t2.Load Game" << endl;
cout << "\t3.Exit" << endl;
cout << "\t";
cin >> choice;
switch (choice)
{
case '1':
newGame();
case '2':
loadGame();
case '3':
break;
}
system("PAUSE");
return 0;
}
Thank you.