first working demo

This commit is contained in:
2024-06-30 03:24:19 -04:00
parent 6dcf0f41e8
commit 12b74f12d4
5 changed files with 22 additions and 46 deletions

View File

@ -1,23 +1,26 @@
#include "map.h"
#include <sstream>
#include <iostream>
#include <fstream>
#include <algorithm>
game_map::game_map(int lvl):
layer{layer_num::map}, map{MAP_HEIGHT}, level{lvl} {
layer{layer_num::map} {
level = lvl;
// TODO: randomly generate a map
}
game_map::game_map(const std::string &map_data, int lvl):
layer{layer_num::map}, map{MAP_HEIGHT}, level{lvl} {
layer{layer_num::map} {
level = lvl;
std::istringstream iss{map_data};
std::string line;
for (int i = 0; i < MAP_HEIGHT; ++i) {
getline(iss, line);
map.push_back(line);
map[i] = line;
}
}
@ -32,7 +35,9 @@ std::vector<position> game_map::get_available_positions() const {
for (int line = 0; line < MAP_HEIGHT; ++line)
for (int x = 0; x < MAP_WIDTH; ++x)
if (map[line][x] == '.')
if (map[line][x] == '.' ||
map[line][x] == '#' ||
map[line][x] == '+')
result.push_back(position{x, line});
return result;
}