10 #include "screenBuffer.h" 47 neighbors[
NORTH] =
nullptr;
48 neighbors[
SOUTH] =
nullptr;
49 neighbors[
EAST] =
nullptr;
50 neighbors[
WEST] =
nullptr;
60 neighbors[direction] = node;
69 if (neighbors[direction] ==
nullptr) {
70 throw std::runtime_error(
"Neighbor not found in the given direction.");
73 neighbors.erase(direction);
82 auto neighbor = neighbors.find(direction);
83 return (neighbor != neighbors.end()) ? neighbor->second :
nullptr;
104 friend class MazeTests::MazeTests;
106 static const int OUT_OF_BOUNDS = -1;
112 std::pair<int, int> start;
113 std::pair<int, int> end;
114 std::pair<int, int> playerPosition;
116 std::map<std::pair<int, int>, std::unique_ptr<MazeNode>> mazeMap;
117 std::set<std::pair<int, int>> inMaze;
124 bool isValidPosition(std::pair<int, int> position)
const;
131 Direction pickRandomDirection(std::vector<Direction>& directions);
138 Direction getOppositeDirection(Direction direction)
const;
145 void linkNodes(std::pair<int, int> start, std::pair<int, int> end);
153 std::vector<std::pair<int, int>> eraseLoop(std::vector<std::pair<int, int>> path, std::pair<int, int> current);
160 std::pair<int, int> nextStep(std::pair<int, int> current);
168 std::vector<std::pair<int, int>> randomWalk(std::pair<int, int> start);
176 void generateMaze(
int width,
int height);
187 void updateMaze(std::pair<int, int> playerPosition);
193 std::pair<std::pair<int, int>, std::pair<int, int>> chooseStartAndEnd();
199 bool checkWin()
const;
206 bool movePlayer(Direction direction);
212 Direction getPlayerInput();
220 Maze(
int width,
int height);
MazeNode * getNeighbor(Direction direction) const
Get the neighboring node in a given direction.
Definition: maze.h:81
std::map< Direction, MazeNode * > getNeighbors() const
Get all neighboring nodes.
Definition: maze.h:90
std::map< Direction, MazeNode * > neighbors
Definition: maze.h:40
A class that represents the screen buffer.
Definition: screenBuffer.h:26
void removeNeighbor(Direction direction)
Remove a neighboring node based on a direction.
Definition: maze.h:68
void addNeighbor(MazeNode *node, Direction direction)
Add a neighboring node with a direction.
Definition: maze.h:59
MazeNode()
Default constructor for MazeNode.
Definition: maze.h:46
A struct that represents the nodes in the graph of the maze.
Definition: maze.h:39
A class that represents the maze game.
Definition: maze.h:101