-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveLoad.cpp
More file actions
54 lines (48 loc) · 1.57 KB
/
SaveLoad.cpp
File metadata and controls
54 lines (48 loc) · 1.57 KB
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
#include"SaveLoad.h"
SaveLoad::SaveLoad(const bool& saveOption, const bool& loadOption, string fName)
{
if (saveOption || loadOption)
openFiles(saveOption, loadOption, fName);
}
void SaveLoad::openFiles(const bool& saveOption, const bool& loadOption, string fName)
{
if (saveOption)
{
stepsFile.open(changeName(fName, "steps"), ios_base::out);
resFile.open(changeName(fName, "result"), ios_base::out);
}
else if (loadOption)
{
stepsFile.open(changeName(fName, "steps"), ios_base::in);
resFile.open(changeName(fName, "result"), ios_base::in);
}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method changes the "screen" to "result" / "steps".
string SaveLoad::changeName(string fName, string ending)
{
string newName = fName.substr(0, fName.size() - 6);
return newName += ending;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method returns what happend from the result file.
char SaveLoad::checkWhatHappend()
{
char temp;
resFile.get(temp);
return temp;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method return time from the result file.
int SaveLoad::getTime()
{
char temp;
int time = 0;
resFile.get(temp);
while (temp != '.')
{
time = 10 * time + temp - '0';
resFile.get(temp);
}
return time;
}