-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveLoad.cpp
45 lines (40 loc) · 1.08 KB
/
SaveLoad.cpp
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
#include "SaveLoad.h"
/*
Writes all relevant game data to a text file.
*/
void SaveLoad::SaveGame(CharacterCreation character) {
ofstream save("savegame.sav");
//Individual stats are seperated by a " ".
for(int i = 0; i < 5; i++) {
save << character.stats[i] << " ";
}
//Other information is seperated by newlines.
save << "\n";
save << character.characterName;
save.close();
}
/*
Reads all relevant game data from a text file.
*/
CharacterCreation SaveLoad::LoadGame(CharacterCreation character) {
int x;
string n;
string t;
ifstream save("savegame.sav");
if(save) {
for(int i = 0; i < 5; i++) {
save >> x;
//cout << x;
character.stats[i] = x;
}
while(!save.eof()) {
save >> n;
t += n + " ";
}
character.characterName = t;
save.close();
} else {
cout << "Save not found/loadable!\n";
}
return character;
}