-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileInput.cpp
50 lines (45 loc) · 1.27 KB
/
FileInput.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
46
47
48
49
50
#include "FileInput.h"
FileInput::FileInput(std::string filename) {
file.open(filename, std::ios_base::in);
if (!file.is_open()) {
current_moves = default_moves;
return;
}
}
FileInput::~FileInput() {
file.close();
}
void FileInput::SetCommands() {
std::string str;
while (getline(file, str)) {
std::string tmp;
char CHAR = '\0';
std::istringstream stream(str);
stream >> tmp >> CHAR;
if (tmp == "RIGHT" && CHAR != '\0') {
current_moves[RIGHT] = CHAR;
}
if (tmp == "LEFT" && CHAR != '\0') {
current_moves[LEFT] = CHAR;
}
if (tmp == "UP" && CHAR != '\0') {
current_moves[UP] = CHAR;
}
if (tmp == "DOWN" && CHAR != '\0') {
current_moves[DOWN] = CHAR;
}
if (tmp == "EXIT" && CHAR != '\0') {
current_moves[EXIT] = CHAR;
}
if (tmp == "SAVE" && CHAR != '\0') {
current_moves[SAVE] = CHAR;
}
if (tmp == "LOAD" && CHAR != '\0') {
current_moves[LOAD] = CHAR;
}
}
CheckAssigment();
std::cout << "Move settings:" << std::endl;
for (auto i : current_moves)
std::cout << i.first << " " << i.second << std::endl;
}