A rectangular 2D boolean array, representing where cars can drive and where they cannot.
More...
#include <Maze.h>
List of all members.
Public Types |
enum | Direction { UP,
DOWN,
LEFT,
RIGHT
} |
| Defines the directions in which movement can happen in the maze. More...
|
Public Member Functions |
| Maze () |
| Creates an empty Maze with width and height of zero.
|
void | generateMaze (const vector< pair< int, int > > &walls, int maxObjectX=0, int maxObjectY=0) |
| Generates a new Maze from the vector of wall coordinates.
|
bool | getSolid (const int &x, const int &y) const |
| Checks if a given position contains a wall or not.
|
int | width () const |
| Provides access to the width of the Maze object.
|
int | height () const |
| Provides access to the height of the Maze object.
|
Static Public Member Functions |
static Direction | backwards (Direction forwards) |
| Inverts a given direction, to give the value to face in the opposite direction.
|
Private Types |
typedef vector< vector< bool > > | BoolGrid |
| Provides an easier to read pseudonym for a 2 dimensional boolean vector.
|
Private Attributes |
BoolGrid | _wallLocations |
| The 2 dimensional vector that stores the locations of walls.
|
int | _width |
| The number of blocks in each row.
|
int | _height |
| The number of blocks in each column.
|
Detailed Description
A rectangular 2D boolean array, representing where cars can drive and where they cannot.
- Author:
- Justin Wernick
-
David Schneider
Definition at line 14 of file Maze.h.
Member Typedef Documentation
Provides an easier to read pseudonym for a 2 dimensional boolean vector.
Definition at line 85 of file Maze.h.
Member Enumeration Documentation
Defines the directions in which movement can happen in the maze.
- Enumerator:
-
Definition at line 20 of file Maze.h.
Constructor & Destructor Documentation
Creates an empty Maze with width and height of zero.
Definition at line 3 of file Maze.cpp.
Member Function Documentation
Inverts a given direction, to give the value to face in the opposite direction.
- Parameters:
-
[in] | forwards | The direction to be inverted. |
- Returns:
- The inverse of the given direction.
Definition at line 57 of file Maze.cpp.
void Maze::generateMaze |
( |
const vector< pair< int, int > > & |
walls, |
|
|
int |
maxObjectX = 0 , |
|
|
int |
maxObjectY = 0 |
|
) |
| |
Generates a new Maze from the vector of wall coordinates.
The size of the Maze is chosen to just fit all of the walls. If objects exist outside of the walls, the x of the rightmost object and the y of the bottommost object can be passed in to make the Maze at least reach those coordinates.
- Parameters:
-
[in] | walls | A vector of x,y coordinate pairs representing the locations of each wall block. |
[in] | maxObjectX | The minimum x value that the Maze must be able to index. |
[in] | maxObjectY | The minimum y value that the Maze must be able to index. |
Definition at line 9 of file Maze.cpp.
bool Maze::getSolid |
( |
const int & |
x, |
|
|
const int & |
y |
|
) |
| const |
Checks if a given position contains a wall or not.
This function is one of the most called as it is called for each block drawing the Maze on the Screen, by any Car checking if it can move, and by the EnemyCar to choose a viable direction to face. As such, it has been optimised by passing the parameters by constant reference, even though they are primitives. Further, the vector class's bounds checking is bypassed, with bounds checking performed manually with the assumption that the 2D vector is rectangular, to increase performance. Neither of these changes impare readability.
- Parameters:
-
[in] | x | The x coordinate being queried. |
[in] | y | The y coordinate being queried. |
- Returns:
- True if the location contains a wall. Also returns true if the coordinate is outside of the Maze.
Definition at line 40 of file Maze.cpp.
int Maze::height |
( |
| ) |
const |
Provides access to the height of the Maze object.
- Returns:
- The amount of blocks in each column of the maze.
Definition at line 52 of file Maze.cpp.
int Maze::width |
( |
| ) |
const |
Provides access to the width of the Maze object.
- Returns:
- The amount of blocks in each row of the maze.
Definition at line 48 of file Maze.cpp.
Member Data Documentation
The number of blocks in each column.
Definition at line 97 of file Maze.h.
The 2 dimensional vector that stores the locations of walls.
The outer vector is columns, indexed with the x coordinate, and the inner vectors are the vertical positions in the column, indexed with the y coordinate. This results in a vector that is acced with _wallLocations.at(x).at(y).
Definition at line 94 of file Maze.h.
The number of blocks in each row.
Definition at line 96 of file Maze.h.
The documentation for this class was generated from the following files: