cirno-puzzle/src/level.h

91 lines
2.4 KiB
C
Raw Normal View History

2020-02-19 12:50:09 -05:00
#ifndef LEVEL_H
#define LEVEL_H
2020-03-19 17:59:21 -04:00
#include <memory>
#include <string>
2020-02-19 12:50:09 -05:00
#include <array>
#include <map>
#include <sstream>
2020-02-19 12:50:09 -05:00
#include "cell.h"
2020-02-19 12:50:09 -05:00
// Very desirable to create module for default values
2020-03-19 17:59:21 -04:00
const std::string default_file_path = "test_map";
2020-02-19 12:50:09 -05:00
/// Abstraction over 2D array to quickly get access to level cells
2020-02-19 12:50:09 -05:00
class Level
{
private:
struct Map
{
using Row = std::vector<CellPtr>;
using Matrix = std::vector<Row>;
enum class SECTION
{
SIZE,
MAP,
TELEPORT,
CHARGE,
TRIGGER,
NONE
};
std::map<std::string, SECTION> map_section =
{
{ "size", SECTION::SIZE },
{ "map", SECTION::MAP },
{ "teleport", SECTION::TELEPORT },
{ "charge", SECTION::CHARGE },
{ "trigger", SECTION::TRIGGER },
{ "", SECTION::NONE }
};
Matrix data;
size_t rows, cols;
std::array<CellPtr, N_CELLS> default_cells;
2020-03-19 17:59:21 -04:00
void init(const std::string &path = default_file_path);
/// Prepare prototypes of default cells
void prepareDefaultCells();
2020-03-19 11:42:45 -04:00
// Map file section readers
void readMapSize(std::istringstream &sstr);
void readMapRow(std::istringstream &sstr);
void readCellSection(std::istringstream &sstr, const SECTION &section);
std::unique_ptr<TeleportCell> &&readTeleport(std::istringstream &sstr, std::unique_ptr<TeleportCell> &&cell);
std::unique_ptr<ChargeCell> &&readCharge(std::istringstream &sstr, std::unique_ptr<ChargeCell> &&cell);
std::unique_ptr<TriggerCell> &&readTrigger(std::istringstream &sstr, std::unique_ptr<TriggerCell> &&cell);
};
2020-02-19 12:50:09 -05:00
Map map;
2020-03-15 11:02:37 -04:00
sf::Color color_ground;
2020-02-19 12:50:09 -05:00
public:
2020-03-19 17:59:21 -04:00
Level(const std::string &path = default_file_path);
2020-03-15 17:57:39 -04:00
/// Number of map rows
size_t rows() const;
/// Number of map columns
size_t cols() const;
2020-02-20 13:34:41 -05:00
/// Get cell at position row, col
CellPtr &getCellAt(coordinate row, coordinate col);
2020-02-20 13:34:41 -05:00
/// Place a bridge cell
2020-02-21 09:13:12 -05:00
void placeBridge(coordinate x, coordinate y);
2020-02-20 13:34:41 -05:00
/// Replace a charge cell with a ground cell
2020-02-21 09:13:12 -05:00
void removeCharge(coordinate x, coordinate y);
2020-03-15 11:02:37 -04:00
/// Get default color for passable cells
sf::Color defaultGroundColor();
/// Set default color for passable cells
void setDefaultGroundColor(const sf::Color &color);
2020-02-19 12:50:09 -05:00
};
#endif // LEVEL_H