-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.cpp
More file actions
160 lines (135 loc) · 4.44 KB
/
Copy pathio.cpp
File metadata and controls
160 lines (135 loc) · 4.44 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
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
#include "io.h"
void printPath(Stack<int> l_path)
{
if (l_path.empty()) {
return;
}
std::cout << l_path.top();
l_path.pop();
while (!l_path.empty()) {
std::cout << "->" << l_path.top();
l_path.pop();
}
std::cout << std::endl;
}
void printCharMap(const CharMap &l_char_map, const std::map<std::string, unsigned short> &l_colours, const std::map<std::string, CharData> &l_characters)
{
for (size_t i = 0; i < l_char_map.back().size(); ++i) {
for (size_t j = 0; j < l_char_map.size(); ++j) {
char ch = l_char_map.at(j).at(l_char_map.back().size() - 1 - i);
if (OS_Windows) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CharData ch_data;
if (ch == l_characters.at("ROAD").character) {
ch_data = l_characters.at("ROAD");
}
else if (ch == l_characters.at("PATH").character) {
ch_data = l_characters.at("PATH");
}
else if (ch == l_characters.at("DEFAULT").character) {
ch_data = l_characters.at("DEFAULT");
}
else if (ch >= 'A' && ch <= 'Z') {
ch_data = l_characters.at("NODE");
}
unsigned short colour;
try {
colour = l_colours.at(ch_data.text_colour)
+ l_colours.at(ch_data.bg_colour) * 16;
}
catch (...) {
std::cout << "Wrong characters entered in map file" << std::endl;
}
SetConsoleTextAttribute(hConsole, colour);
}
std::cout << ch << ' ';
}
std::cout << std::endl;
}
}
void handleIO(const Map &l_map, const std::map<std::string, unsigned short> &l_colours, const std::map<std::string, CharData> &l_characters)
{
while (true) {
printCharMap(l_map.getCharMap(), l_colours, l_characters);
std::cout << std::endl;
if (OS_Windows) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, l_colours.at("White"));
}
std::cout << "Enter starting and ending positions, or '~' to quit" << std::endl;
char in_ch1;
std::cin >> in_ch1;
if (in_ch1 == '~') {
break;
}
char in_ch2;
std::cin >> in_ch2;
std::cout << std::endl;
printCharMap(l_map.getCharMapWithPath(in_ch1, in_ch2), l_colours, l_characters);
std::cout << std::endl;
if (OS_Windows) {
system("pause");
system("cls");
}
}
}
Colours loadColours()
{
Colours colours;
if (OS_Windows) {
std::ifstream ifs_colour("config/colour_encoding.config");
if (!ifs_colour.is_open()) {
std::cout << "Couldn't load colour config" << std::endl;
}
unsigned short counter = 0;
std::string line;
while (std::getline(ifs_colour, line)) {
std::stringstream sstream(line);
std::string key;
sstream >> key;
colours[key] = counter;
++counter;
}
}
return colours;
}
CharDataSet loadCharConfig()
{
CharDataSet characters;
std::ifstream ifs_char("config/character_encoding.config");
if (!ifs_char.is_open()) {
std::cout << "Couldn't load character config" << std::endl;
}
std::string line;
while (std::getline(ifs_char, line)) {
std::stringstream sstream(line);
std::string key;
std::string ch_str;
std::string txt_colour;
std::string bg_colour;
sstream >> key >> ch_str >> txt_colour >> bg_colour;
char ch;
if (ch_str.at(0) == '\'') {
ch = ch_str.at(1);
}
else {
ch = static_cast<char>(std::stoi(ch_str));
}
characters[key] = {ch, txt_colour, bg_colour};
}
return characters;
}
Map loadMap(const std::map<std::string, CharData> &l_characters)
{
Map map;
std::ifstream ifs("maps/map1.map");
if (!ifs.is_open()) {
std::cout << "Couldn't load map" << std::endl;
}
map.setCharMapEncoding(l_characters.at("ROAD").character,
l_characters.at("PATH").character,
l_characters.at("NODE").character);
map.load(ifs);
ifs.close();
return map;
}