30 std::ifstream file(filename.c_str());
32 if (!(file.is_open()))
45 std::string metadata_buffer;
46 std::string level_buffer;
50 std::string current_line =
"";
52 while (std::getline(file, current_line))
56 current_line = Utils::String::trim(current_line);
60 if (current_line !=
"start")
61 metadata_buffer += (current_line +
'\n');
66 bool parsed_level =
false;
68 while (std::getline(file, current_line))
72 current_line = Utils::String::trim(current_line);
74 if (current_line ==
"end")
80 level_buffer += (current_line +
'\n');
88 "Abrupt ending of file while parsing level at line " +
89 Utils::String::toString(line_count)
99 int player_start_x = 1;
100 int player_start_y = 1;
105 std::vector<std::vector<bool> > rawBoard;
108 std::vector<std::string> level_lines = Utils::String::split(level_buffer,
'\n');
110 for (
size_t j = 0; j < (level_lines.size()); j++)
112 current_line = level_lines[j];
114 if (current_line.empty())
117 std::vector<bool> rawBoardLine;
123 for (
size_t i = 0; i < current_line.size(); i++)
125 if (current_line[i] == SNAKE_CHAR)
128 player_start_y = rawBoard.size();
131 rawBoardLine.push_back(
false);
134 rawBoardLine.push_back(current_line[i] == WALL_CHAR);
138 rawBoard.push_back(rawBoardLine);
143 int board_width = rawBoard[0].size();
144 int board_height = rawBoard.size();
148 ((Globals::Game::teleport) ?
154 board->setStartX(player_start_x);
155 board->setStartY(player_start_y);
159 std::stringstream stream;
160 stream << metadata_buffer;