You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.0 KiB
C++

#ifndef LEVEL_H
#define LEVEL_H
#include <array>
#include <map>
#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<CellPtr>;
using Matrix = std::vector<Row>;
enum class SECTION
{
SIZE,
MAP,
TELEPORT,
TRIGGER,
NONE
};
std::map<std::string, SECTION> map_section =
{
{ "size", SECTION::SIZE },
{ "map", SECTION::MAP },
{ "teleport", SECTION::TELEPORT },
{ "trigger", SECTION::TRIGGER },
{ "", SECTION::NONE }
};
Matrix data;
size_t rows, cols;
std::array<CellPtr, N_CELLS> 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