summaryrefslogtreecommitdiff
path: root/source/logic/Maze.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/logic/Maze.cpp')
-rw-r--r--source/logic/Maze.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/source/logic/Maze.cpp b/source/logic/Maze.cpp
new file mode 100644
index 0000000..ab24035
--- /dev/null
+++ b/source/logic/Maze.cpp
@@ -0,0 +1,77 @@
+#include "Maze.h"
+
+Maze::Maze()
+ :_width(0),
+ _height(0)
+{
+}
+
+void Maze::generateMaze(const vector<pair<int,int> >& walls, int maxObjectX, int maxObjectY)
+{
+ //find bounds so that rectangular vector can be generated
+ int maxX = maxObjectX;
+ int maxY = maxObjectY;
+ for (vector<pair<int,int> >::const_iterator iter = walls.begin(); iter!=walls.end(); ++iter)
+ {
+ if (iter->first > maxX) maxX = iter->first;
+ if (iter->second > maxY) maxY = iter->second;
+ }
+ _width = maxX+1; //need to convert from highest index to required size
+ _height = maxY+1;
+
+
+ _wallLocations.clear();
+
+ for (int x=0; x<_width; ++x)
+ {
+ _wallLocations.push_back(vector<bool>());
+ for (int y=0; y<_height; ++y)
+ {
+ _wallLocations.back().push_back(false);
+ }
+ }
+
+ for (vector<pair<int,int> >::const_iterator iter = walls.begin(); iter!=walls.end(); ++iter)
+ {
+ _wallLocations.at(iter->first).at(iter->second) = true;
+ }
+}
+
+bool Maze::getSolid(const int& x, const int& y) const
+{
+ if (x<0 || y<0) return true;
+ if (x>=width() || y>=height()) return true;
+ //bounds have already been checked, can use more efficient, less safe, indexing
+ return _wallLocations[x][y];
+}
+
+int Maze::width() const
+{
+ return _width;
+}
+int Maze::height() const
+{
+ return _height;
+}
+
+Maze::Direction Maze::backwards(Direction forwards)
+{
+ Direction backwards;
+ switch (forwards)
+ {
+ case LEFT:
+ backwards = RIGHT;
+ break;
+ case RIGHT:
+ backwards = LEFT;
+ break;
+ case UP:
+ backwards = DOWN;
+ break;
+ case DOWN:
+ backwards = UP;
+ break;
+ }
+
+ return backwards;
+}