-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecord.cpp
More file actions
54 lines (45 loc) · 1.52 KB
/
Record.cpp
File metadata and controls
54 lines (45 loc) · 1.52 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
54
#include "Record.h"
namespace Record {
void saveToFile(Player *player, vector<Room> &MAP) {
ofstream record("Record.txt");
try{
string Warning;
if(!record) throw (Warning="Open File Fail!");
}catch(string Warning){
cout << Color::RED << Warning << Color::Default << '\n';
}
player->saveFile(record);
record << MAP.size() << '\n';
for (Room room:MAP)
room.saveFile(record);
}
void loadFromFile(Player *player,vector<Room> &MAP){
ifstream record("Record.txt");
try{
string Warning;
if(!record) throw (Warning="Open File Fail!");
}catch(string Warning){
cout << Color::RED << Warning << Color::Default << '\n';
}
player->loadFile(record);
int SZ;
record >> SZ;
for(int i=0;i<SZ;++i){
Room room;
room.loadFile(record);
MAP.push_back(room);
}
player->setCurrentRoom(&MAP[player->getCur()]);
player->setPreviousRoom(&MAP[player->getPre()]);
for(int i=0;i<SZ;++i){
if(MAP[i].getUp()!=-1)
MAP[i].setUpRoom(&MAP[MAP[i].getUp()]);
if(MAP[i].getDown()!=-1)
MAP[i].setDownRoom(&MAP[MAP[i].getDown()]);
if(MAP[i].getLeft()!=-1)
MAP[i].setLeftRoom(&MAP[MAP[i].getLeft()]);
if(MAP[i].getRight()!=-1)
MAP[i].setRightRoom(&MAP[MAP[i].getRight()]);
}
}
}