A customisable maze generator for C++ and JavaScript.
##########################################
## ## ## ##
## ## ########## ###### ########## ##
## ## ## ## ## ## ## ##
## ## ###### ## ## ###### ## ## ##
## ## ## ## ## ## ##
## ########## ## ########## ###### ##
## ## ## ## ## ## ##
## ###### ## ## ## ## ## ## ######
## ## ## ## ## ## ##
###### ## ## ###################### ##
## ## ## ## ## ##
## ################## ## ## ##########
## ## ##
## ################################## ##
## ## ## ## ##
###### ## ## ############## ## ## ##
## ## ## ## ## ## ## ##
## ###### ###### ## ## ## ## ## ##
## ## ## ## ## ##
##########################################
- for c++
- gcc compiler
- c++ 2011 standard (
-std=c++11
)
- for javascript
-
Include MazeGenerator in your main application
// c++: #include "../MazeGenerator.cpp" // javascript: const MazeGenerator = require("../MazeGenerator.js");
-
Define variables
// c++: MazeGenerator maze; // or // MazeGenerator maze(x, y); MazeGenerator maze(20, 10); // javascript: const maze = new MazeGenerator(); // or // const maze = new MazeGenerator(x, y); const maze = new MazeGenerator(20, 10); // where 'x' is the width of the maze and 'x' is the height;
-
Generate a maze
// c++ and javascript maze.generate();
-
Draw maze in console
// c++ and javascript maze.draw(); // or // maze.draw(spaceString, wallString); maze.draw(" ", "##");
-
Result:
################################################################################## ## ## ## ## ## ## ## ## ########## ## ###### ## ###### ################## ########## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ###### ###################################### ## ## ###### ###### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ########## ## ###### ############## ########## ## ## ## ###### ## ## ## ## ## ## ## ## ## ## ## ###### ########## ## ###### ## ########## ###### ########## ########## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ########## ########## ########## ########## ############## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ###### ########## ###### ############## ###### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ################## ## ## ###### ## ## ## ## ###### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ########## ## ## ########## ## ########## ########## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ########################## ## ## ## ## ## ################## ## ## ## ## ## ## ## ## ## ##################################################################################
-
Get a 2D
bool
array representingspaces
andwalls
// c++: vector < vector < bool >> matrix = maze.get(); // javascript: const matrix = maze.get();
How to run demo
files:
// c++:
cd c++/demo
g++ -std=c++11 'demo.cpp' -o 'demo' && './demo'
// javascript
cd js/demo
node demo.js