/Maze-Generator

A customisable maze generator for C++ and JavaScript

Primary LanguageC++Apache License 2.0Apache-2.0

Maze-Generator

A customisable maze generator for C++ and JavaScript.

##########################################
##  ##                  ##              ##
##  ##  ##########  ######  ##########  ##
##  ##  ##      ##  ##      ##      ##  ##
##  ##  ######  ##  ##  ######  ##  ##  ##
##  ##          ##  ##          ##  ##  ##
##  ##########  ##  ##########  ######  ##
##          ##  ##  ##      ##  ##      ##
##  ######  ##  ##  ##  ##  ##  ##  ######
##      ##  ##  ##      ##      ##      ##
######  ##  ##  ######################  ##
##      ##  ##          ##  ##          ##
##  ##################  ##  ##  ##########
##                          ##          ##
##  ##################################  ##
##      ##  ##                  ##      ##
######  ##  ##  ##############  ##  ##  ##
##      ##  ##      ##      ##  ##  ##  ##
##  ######  ######  ##  ##  ##  ##  ##  ##
##          ##      ##  ##          ##  ##
##########################################

Requirements

  • for c++
    • gcc compiler
    • c++ 2011 standard (-std=c++11)
  • for javascript

How to use it

  1. Include MazeGenerator in your main application

    // c++:
    #include "../MazeGenerator.cpp"
    
    // javascript:
    const MazeGenerator = require("../MazeGenerator.js");
  2. 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;
  3. Generate a maze

    // c++ and javascript
    maze.generate();
  4. Draw maze in console

    // c++ and javascript
    maze.draw();
    
    // or
    // maze.draw(spaceString, wallString);
    maze.draw("  ", "##");
  5. Result:

    ##################################################################################
    ##                  ##          ##          ##                                  ##
    ##  ##  ##  ##########  ##  ######  ##  ######  ##################  ##########  ##
    ##  ##  ##  ##          ##          ##          ##          ##  ##          ##  ##
    ##  ##  ######  ######################################  ##  ##  ######  ######  ##
    ##  ##  ##      ##          ##                          ##  ##  ##  ##  ##      ##
    ##  ##  ##  ##########  ##  ######  ##############  ##########  ##  ##  ##  ######
    ##  ##  ##          ##  ##      ##              ##  ##          ##      ##      ##
    ######  ##########  ##  ######  ##  ##########  ######  ##########  ##########  ##
    ##      ##      ##      ##      ##          ##      ##          ##          ##  ##
    ##  ##  ##  ##  ##########  ##########  ##########  ##########  ##############  ##
    ##  ##  ##  ##  ##      ##          ##  ##                  ##      ##      ##  ##
    ##  ##  ##  ##  ######  ##########  ######  ##############  ######  ##  ##  ##  ##
    ##  ##      ##          ##      ##      ##      ##  ##      ##  ##  ##  ##  ##  ##
    ##  ##################  ##  ##  ######  ##  ##  ##  ##  ######  ##  ##  ##  ##  ##
    ##      ##      ##      ##  ##  ##      ##  ##  ##  ##          ##      ##  ##  ##
    ##  ##  ##  ##  ##########  ##  ##  ##########  ##  ##########  ##########  ##  ##
    ##  ##      ##              ##  ##  ##      ##  ##              ##      ##  ##  ##
    ##  ##########################  ##  ##  ##  ##  ##  ##################  ##  ##  ##
    ##                          ##          ##      ##                      ##      ##
    ##################################################################################
  6. Get a 2D bool array representing spaces and walls

    // c++:
    vector < vector < bool >> matrix = maze.get();
    
    // javascript:
    const matrix = maze.get();

Demo

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

Inspiration