WORK IN PROGRESS

TODO: implement random level generation
moved exclude from list to position.h
distinguished level and map
This commit is contained in:
2024-07-12 00:16:08 -04:00
parent c68330b3e3
commit b3300b8e7c
13 changed files with 268 additions and 113 deletions

View File

@ -12,49 +12,70 @@
#include "display.h"
#include "position.h"
#include "characters.h"
#include "rng.h"
class game_map final {
private:
const feature enabled_features;
std::vector<char> map;
// IMPORTANT: keep empty_spots ordered
position_list empty_spots;
position up_stairs;
position down_stairs;
int room_cnt;
public:
game_map(int lvl = 0); // randomly generate one
// initialize using stored data
game_map(const std::string &map_data, int lvl);
~game_map(); // placeholder
// randomly generate a map
game_map(RNG &rng, const feature enabled_features);
// read map from a string
game_map(const std::string &map_data, RNG &rng,
const feature enabled_features);
int get_level() const;
position_list get_available_positions() const;
const position_list get_available_positions() const;
const std::vector<position_list> get_room_list() const;
// IMPORTANT: always print a map before anything else
void print(display &out) const;
// prints using ncurses
void print() const;
position get_up_stairs() const;
position get_down_stairs() const;
// prints to a string
void print(display &display) const;
int get_up_stairs_room() const;
int get_down_stairs_room() const;
private:
position remap_index(const int idx) const {
return {idx % MAP_WIDTH, idx / MAP_HEIGHT};
}
// This is implemented this way to do two things:
// 1. avoid directly accessing heap memory (bonus points)
// 2. make a level revisitable
void apply_potion(character *who, const stat_name statn, const int amount);
// just in case you want to retain the potion effects
void enter_level(character *who);
void leave_level(character *who);
public:
struct effect {
character *who;
stat_name statn;
int amount;
};
std::string map[MAP_HEIGHT];
int level;
// use this to remember every applied potion
std::vector<effect> effects;
int remap_position(const position &pos) const {
return pos.y * MAP_WIDTH + pos.x;
}
};
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|-----------------------------------------------------------------------------|";
"|-----------------------------------------------------------------------------|\
| |\
| |--------------------------| |-----------------------| |\
| |11111111111111111111111111| |33333333333333333333333| |\
| |11111111111111111111111111+########+33333333333333333333333|-------| |\
| |11111111111111111111111111| # |3333333333333333333333333333333|--| |\
| |11111111111111111111111111| # |3333333333333333333333333333333333|--| |\
| |----------+---------------| # |----+----------------|333333333333333| |\
| # ############# |333333333333333| |\
| # # |-----+------| |333333333333333| |\
| # # |444444444444| |333333333333333| |\
| ################### |444444444444| ######+333333333333333| |\
| # # |444444444444| # |333333333333333| |\
| # # |-----+------| # |--------+------| |\
| |---------+-----------| # # # # |\
| |222222222222222222222| # # # |----+------| |\
| |222222222222222222222| ######################## |00000000000| |\
| |222222222222222222222| # # |00000000000| |\
| |222222222222222222222| # |------+--------------------|00000000000| |\
| |222222222222222222222| # |000000000000000000000000000000000000000| |\
| |222222222222222222222+##########+000000000000000000000000000000000000000| |\
| |222222222222222222222| |000000000000000000000000000000000000000| |\
| |---------------------| |---------------------------------------| |\
| |\
|-----------------------------------------------------------------------------|";
#endif