#include "Maze.h" Maze::Maze() :_width(0), _height(0) { } void Maze::generateMaze(const vector >& walls, int maxObjectX, int maxObjectY) { //find bounds so that rectangular vector can be generated int maxX = maxObjectX; int maxY = maxObjectY; for (vector >::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()); for (int y=0; y<_height; ++y) { _wallLocations.back().push_back(false); } } for (vector >::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; }