1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#include <iostream>
#include "function.h"
#include <fstream>
#include <sstream>
#include <cmath>
using namespace std;
bool loadGame(bool finished)
{
string inputChoice;
string saveNames;
int playerInfoTemp[10];
string infoTemp;
string saveNameString[10];
playerInformation playerChar;
int i=0;
int HPTemp;
bool success=0;
cout << "You chose to load a game!" << endl;
ifstream ifile;
ifile.open(string("saveGameFile.txt").c_str());
do{
cout << "Save Games:" << endl << endl;
while(!ifile.eof() and i<=9)
{
getline(ifile, saveNames);
cout << saveNames << endl;
saveNameString[i]=saveNames;
i++;
}
i=0;
cout << endl << endl;
cout << "Which save game would you like to load?" << endl;
(cin >> inputChoice).get();
while(i<=9 and success==0)
{
if((saveNameString[i])==inputChoice)
{
cout << "Found the save file!" << endl << endl;
success=1;
}
else
{
cout << "save file not found! \nTry again:" << endl << endl;
i++;//ADDED LATE AT NIGHT! CHECK THIS!
}
}
}while(success==0);
ifile.close();
ifile.open(string(inputChoice+".txt").c_str());
i=0;
getline(ifile, playerChar.firstName);
cout << "First name: " << playerChar.firstName << endl;
getline(ifile, playerChar.lastName);
cout << "Last name: " << playerChar.lastName << endl;
getline(ifile, playerChar.race);
cout << "Race: " << playerChar.race << endl;
getline(ifile, playerChar.playerClass);
cout << "Class: " << playerChar.playerClass << endl;
for(i=0; i<=9; i++)
playerInfoTemp[i]=0;
getline(ifile, infoTemp);
i=1;
while(i<=infoTemp.length())
{
playerInfoTemp[i-1]=infoTemp.at(i-1)-'0';
i++;
}
playerChar.playerHP=0;
for(i=0; i<=infoTemp.length()-1; i++)
{
if(i==0)
{
playerChar.playerHP+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
}
else if(i>=1 and i<infoTemp.length())
{
playerChar.playerHP+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
}
else if(i==infoTemp.length()-1)
{
playerChar.playerHP+=playerInfoTemp[i];
}
}
if(DEBUG_loadGame==1)
cout << "Player HP: " << playerChar.playerHP << endl;
for(i=0; i<=9; i++)
playerInfoTemp[i]=0;
getline(ifile, infoTemp);
i=1;
while(i<=infoTemp.length())
{
playerInfoTemp[i-1]=infoTemp.at(i-1)-'0';
i++;
}
playerChar.playerMP=0;
for(i=0; i<=infoTemp.length()-1; i++)
{
if(i==0)
{
playerChar.playerMP+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
}
else if(i>=1 and i<infoTemp.length())
{
playerChar.playerMP+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
}
else if(i==infoTemp.length()-1)
{
playerChar.playerMP+=playerInfoTemp[i];
}
}
if(DEBUG_loadGame==1)
cout << "Player MP: " << playerChar.playerMP << endl;
for(i=0; i<=9; i++)
playerInfoTemp[i]=0;
getline(ifile, infoTemp);
i=1;
while(i<=infoTemp.length())
{
playerInfoTemp[i-1]=infoTemp.at(i-1)-'0';
i++;
}
playerChar.playerDefense=0;
for(i=0; i<=infoTemp.length()-1; i++)
{
if(i==0)
{
playerChar.playerDefense+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
}
else if(i>=1 and i<infoTemp.length())
{
playerChar.playerDefense+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
}
else if(i==infoTemp.length()-1)
{
playerChar.playerDefense+=playerInfoTemp[i];
}
}
if(DEBUG_loadGame==1)
cout << "Player Defense: " << playerChar.playerDefense << endl;
for(i=0; i<=9; i++)
playerInfoTemp[i]=0;
getline(ifile, infoTemp);
i=1;
while(i<=infoTemp.length())
{
playerInfoTemp[i-1]=infoTemp.at(i-1)-'0';
i++;
}
playerChar.playerAttack=0;
for(i=0; i<=infoTemp.length()-1; i++)
{
if(i==0)
{
playerChar.playerAttack+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
}
else if(i>=1 and i<infoTemp.length())
{
playerChar.playerAttack+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
}
else if(i==infoTemp.length()-1)
{
playerChar.playerAttack+=playerInfoTemp[i];
}
}
if(DEBUG_loadGame==1)
cout << "Player Attack: " << playerChar.playerAttack << endl;
ifile.close();
}
|