31 std::ifstream file(filename.c_str());
33 if (!(file.is_open()))
46 std::string metadata_buffer;
47 std::string level_buffer;
51 std::string current_line =
"";
53 while (std::getline(file, current_line))
57 current_line = Utils::String::trim(current_line);
61 if (current_line !=
"start")
62 metadata_buffer += (current_line +
'\n');
67 bool parsed_level =
false;
69 while (std::getline(file, current_line))
73 current_line = Utils::String::trim(current_line);
75 if (current_line ==
"end")
81 level_buffer += (current_line +
'\n');
89 "Abrupt ending of file while parsing level at line " +
90 Utils::String::toString(line_count)
100 int player_start_x = 1;
101 int player_start_y = 1;
106 std::vector<std::vector<bool> > rawBoard;
109 std::vector<std::string> level_lines = Utils::String::split(level_buffer,
'\n');
111 for (
size_t i = 0; i < level_lines.size(); ++i)
112 level_lines[i] = Utils::String::trim(level_lines[i]);
114 for (
size_t j = 0; j < (level_lines.size()); j++)
116 current_line = level_lines[j];
118 if (current_line.empty())
121 std::vector<bool> rawBoardLine;
127 for (
size_t i = 0; i < current_line.size(); i++)
129 if (current_line[i] == SNAKE_CHAR)
132 player_start_y = rawBoard.size();
135 rawBoardLine.push_back(
false);
138 rawBoardLine.push_back(current_line[i] == WALL_CHAR);
142 rawBoard.push_back(rawBoardLine);
147 int board_width = rawBoard[0].size();
148 int board_height = rawBoard.size();
152 ((Globals::Game::teleport) ?
158 board->setStartX(player_start_x);
159 board->setStartY(player_start_y);
163 std::stringstream stream;
164 stream << metadata_buffer;
165 INI::Parser parser(stream);