MiniGame-Madness
maze.h
Go to the documentation of this file.
1 #ifndef MAZE_H
2 #define MAZE_H
3 
10 #include "screenBuffer.h"
11 #include <map>
12 #include <memory>
13 
18 enum NodeType {
19  NONE,
20  Path,
21  Wall,
22 };
23 
28 enum Direction {
31  EAST,
32  WEST,
33 };
34 
40 struct MazeNode {
42  std::map<Direction, MazeNode*> neighbors;
48  MazeNode() : type(NodeType::NONE){}
49 
55  void addNeighbor(MazeNode* node, Direction direction) {
56  if (neighbors.find(direction) != neighbors.end()) {
57  throw std::runtime_error("Neighbor already exists in the given direction.");
58  }
59 
60  neighbors[direction] = node;
61  }
62 
67  bool removeNeighbor(Direction direction) {
68  if (neighbors.find(direction) == neighbors.end()) {
69  throw std::runtime_error("Neighbor not found in the given direction.");
70  }
71 
72  neighbors.erase(direction);
73  }
74 
80  MazeNode* getNeighbor(Direction direction) const {
81  auto neighbor = neighbors.find(direction);
82  return (neighbor != neighbors.end()) ? neighbor->second : nullptr;
83  }
84 
89  std::map<Direction, MazeNode*> getNeighbors() const {
90  return neighbors;
91  }
92 
93 
99  return type;
100  }
101 
107  bool setNodeType(NodeType type) {
108  this->type = type;
109  return true;
110  }
111 };
112 
119 class Maze {
120  private:
121  int WIDTH;
122  int HEIGHT;
123  std::map<std::pair<int, int>, MazeNode*> mazeMape;
124 
131  void generateMaze(int width, int height);
132 
133 public :
134 
139  Maze();
140 
146  Maze(int width, int height);
147 
148 
149 };
150 
151 
152 #endif // MAZE_H
MazeNode * getNeighbor(Direction direction) const
Get the neighboring node in a given direction.
Definition: maze.h:80
std::map< Direction, MazeNode * > getNeighbors() const
Get all neighboring nodes.
Definition: maze.h:89
Definition: maze.h:20
NodeType
An enumeration of the different types of nodes in the maze.
Definition: maze.h:18
Definition: maze.h:21
std::map< Direction, MazeNode * > neighbors
Definition: maze.h:42
bool setNodeType(NodeType type)
Set the piece type of the node.
Definition: maze.h:107
Definition: maze.h:29
Definition: maze.h:31
Definition: maze.h:19
bool removeNeighbor(Direction direction)
Remove a neighboring node with a direction.
Definition: maze.h:67
Definition: maze.h:30
void addNeighbor(MazeNode *node, Direction direction)
Add a neighboring nodes with a direction.
Definition: maze.h:55
MazeNode()
Default constructor for MazeNode.
Definition: maze.h:48
NodeType getNodeType() const
Get the piece type of the node.
Definition: maze.h:98
A struct that reprsents the nodes in the graph of the maze.
Definition: maze.h:40
NodeType type
Definition: maze.h:41
Definition: maze.h:32
A class that represents the maze game.
Definition: maze.h:119