first working demo
This commit is contained in:
13
src/map.cc
13
src/map.cc
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user