first working demo
This commit is contained in:
@ -9,7 +9,7 @@ void display::clear() {
|
||||
|
||||
void display::print(std::ostream &out) const {
|
||||
for (auto line : contents)
|
||||
out << line << std::endl;
|
||||
out << line;
|
||||
}
|
||||
|
||||
void display::print_line(const std::string &line, const int linenum) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <ncurses.h>
|
||||
#include "map.h"
|
||||
#include "races.h"
|
||||
#include "display.h"
|
||||
@ -23,6 +24,8 @@ int main() {
|
||||
display.clear();
|
||||
mmap->print(display);
|
||||
display.print_position(player->get_position(), '@');
|
||||
display.print(cout);
|
||||
cout << "Command: " << ch << endl;
|
||||
|
||||
auto available_positions = mmap->get_available_positions();
|
||||
|
||||
|
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;
|
||||
}
|
||||
|
31
src/map.h
31
src/map.h
@ -42,14 +42,14 @@ public:
|
||||
// just in case you want to retain the potion effects
|
||||
void enter_level(character *who);
|
||||
void leave_level(character *who);
|
||||
private:
|
||||
public:
|
||||
struct effect {
|
||||
character *who;
|
||||
stat_name statn;
|
||||
int amount;
|
||||
};
|
||||
|
||||
std::vector<std::string> map;
|
||||
std::string map[MAP_HEIGHT];
|
||||
int level;
|
||||
|
||||
// use this to remember every applied potion
|
||||
@ -57,31 +57,6 @@ private:
|
||||
};
|
||||
|
||||
const std::string default_map =
|
||||
"|-----------------------------------------------------------------------------|\
|
||||
| |\
|
||||
| |--------------------------| |-----------------------| |\
|
||||
| |..........................| |.......................| |\
|
||||
| |..........................+########+.......................|-------| |\
|
||||
| |..........................| # |...............................|--| |\
|
||||
| |..........................| # |..................................|--| |\
|
||||
| |----------+---------------| # |----+----------------|...............| |\
|
||||
| # ############# |...............| |\
|
||||
| # # |-----+------| |...............| |\
|
||||
| # # |............| |...............| |\
|
||||
| ################### |............| ######+...............| |\
|
||||
| # # |............| # |...............| |\
|
||||
| # # |-----+------| # |--------+------| |\
|
||||
| |---------+-----------| # # # # |\
|
||||
| |.....................| # # # |----+------| |\
|
||||
| |.....................| ######################## |...........| |\
|
||||
| |.....................| # # |...........| |\
|
||||
| |.....................| # |------+--------------------|...........| |\
|
||||
| |.....................| # |.......................................| |\
|
||||
| |.....................+##########+.......................................| |\
|
||||
| |.....................| |.......................................| |\
|
||||
| |---------------------| |---------------------------------------| |\
|
||||
| |\
|
||||
|-----------------------------------------------------------------------------|\
|
||||
";
|
||||
"|-----------------------------------------------------------------------------|\n| |\n| |--------------------------| |-----------------------| |\n| |..........................| |.......................| |\n| |..........................+########+.......................|-------| |\n| |..........................| # |...............................|--| |\n| |..........................| # |..................................|--| |\n| |----------+---------------| # |----+----------------|...............| |\n| # ############# |...............| |\n| # # |-----+------| |...............| |\n| # # |............| |...............| |\n| ################### |............| ######+...............| |\n| # # |............| # |...............| |\n| # # |-----+------| # |--------+------| |\n| |---------+-----------| # # # # |\n| |.....................| # # # |----+------| |\n| |.....................| ######################## |...........| |\n| |.....................| # # |...........| |\n| |.....................| # |------+--------------------|...........| |\n| |.....................| # |.......................................| |\n| |.....................+##########+.......................................| |\n| |.....................| |.......................................| |\n| |---------------------| |---------------------------------------| |\n| |\n|-----------------------------------------------------------------------------|";
|
||||
|
||||
#endif
|
||||
|
@ -31,22 +31,15 @@ bool position::operator<(const position &other) const {
|
||||
return y < other.y || x < other.x;
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
|
||||
size_t find(const std::vector<position> &sorted_list,
|
||||
const position &target) {
|
||||
int l = 0;
|
||||
int r = sorted_list.size() - 1;
|
||||
// TODO: implement binary searching
|
||||
|
||||
while (l <= r) {
|
||||
int mid = l + (l + r) / 2;
|
||||
|
||||
if (target == sorted_list[mid])
|
||||
return mid;
|
||||
|
||||
if (target < sorted_list[mid])
|
||||
l = mid + 1;
|
||||
else
|
||||
r = mid - 1;
|
||||
}
|
||||
for (size_t i = 0; i < sorted_list.size(); ++i)
|
||||
if (sorted_list[i] == target)
|
||||
return i;
|
||||
|
||||
return sorted_list.size();
|
||||
}
|
||||
|
Reference in New Issue
Block a user