#ifndef LEVEL_H #define LEVEL_H #include #include #include "cell.h" // Very desirable to create module for default values const std::string default_map_file_name = "test_map"; /// Abstraction over 2D array to quickly get access to level cells class Level { private: struct Map { using Row = std::vector; using Matrix = std::vector; enum class SECTION { SIZE, MAP, TELEPORT, TRIGGER, NONE }; std::map map_section = { { "size", SECTION::SIZE }, { "map", SECTION::MAP }, { "teleport", SECTION::TELEPORT }, { "trigger", SECTION::TRIGGER }, { "", SECTION::NONE } }; Matrix data; size_t rows, cols; std::array default_cells; void init(const std::string &map_file_name = default_map_file_name); /// Prepare prototypes of default cells void prepareDefaultCells(); /// Map file section readers void readMapSize(std::istringstream &sstr); void readMapRow(std::istringstream &sstr); void readTeleport(std::istringstream &sstr); void readTrigger(std::istringstream &sstr); }; Map map; sf::Color color_ground; public: Level(const std::string &map_file_name = default_map_file_name); /// Number of map rows size_t rows() const; /// Number of map columns size_t cols() const; /// Get cell at position row, col CellPtr &getCellAt(coordinate row, coordinate col); /// Place a bridge cell void placeBridge(coordinate x, coordinate y); /// Replace a charge cell with a ground cell void removeCharge(coordinate x, coordinate y); /// Get default color for passable cells sf::Color defaultGroundColor(); /// Set default color for passable cells void setDefaultGroundColor(const sf::Color &color); }; #endif // LEVEL_H