node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »

@mitchallen/maze-generator-core

@mitchallen/maze-generator-core

maze generator core

Version Coverage Status Version


Installation

You must use npm 2.7.0 or higher because of the scoped package name.

$ npm init
$ npm install @mitchallen/maze-generator-core --save

Usage

var cgFactory = require("@mitchallen/connection-grid-square"),
    mazeCore = require("@mitchallen/maze-generator-core");

spec = spec || {};

let _x = spec.x || 5;
let _y = spec.y || 6;

let _gridSpec = {
    x: _x,
    y: _y
};

var _connectionGrid = cgFactory.create(_gridSpec);
if(!_connectionGrid) {
    return null;
}

var maze = mazeCore.create( {
    grid: _connectionGrid,
});

maze.generate();

Browser Usage

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Maze Generator Core Example</title>
    <meta name="description" content="Maze Generator Core Example">
    <!-- either cdn should work -->
    <!--
    <script src="https://cdn.rawgit.com/mitchallen/maze-generator-core/v0.1.7/dist/maze-generator-core.min.js"></script>
    -->
    <script src="https://unpkg.com/@mitchallen/maze-generator-core@0.1.7/dist/maze-generator-core.min.js"></script>
    <script src="https://unpkg.com/@mitchallen/connection-grid-square@0.1.9/dist/connection-grid-square.min.js"></script>
    <script>
      var cgFactory = window.MitchAllen.ConnectionGridSquare;
      console.log(cgFactory);
      var xSize = 10, ySize = 5;
      var cGrid = cgFactory.create( { x: xSize, y: ySize } );
      var factory = window.MitchAllen.MazeGeneratorCore;
      var sm = factory.create({
        grid: cGrid,
      });
      console.log(sm);
      sm.generate();
      sm.log();  
    </script>
  </head>
  <body>
    <h1>Maze Generator Core Example</h1>
    <p>See JavaScript developer console for output.</p>
  </body>
</html>

Modules

maze-generator-core@mitchallen/connection-grid-core

Maze Generator Core generated by create

maze-generator-core-factory

A factory for generating maze generator core objects

External

@mitchallen/connection-grid-core

Connection Grid Core

maze-generator-core ⇐ @mitchallen/connection-grid-core

Maze Generator Core generated by create

Extends: @mitchallen/connection-grid-core

maze-generator-core.afterGenerate(spec)

Method called after generate generates a maze. This should be overriden by base class. The spec parameter will be passed on to this method after the maze has been generated. The derived method should parse spec for needed values.

Kind: instance method of maze-generator-core

Param Type Description
spec Object Named parameters for method

Example (possible usage)

// A derived object would have an afterGenerate method that parses spec.open 
let spec = {
   open: [
     { border: "N", list: [ 0, 2 ] },
     { border: "S", list: [ 3 ] }
   ]
};
mazeGenerator.generate(spec);

maze-generator-core.generate(options) ⇒ boolean

Generators a maze

Kind: instance method of maze-generator-core

Param Type Description
options Object Named parameters for generating a maze
options.mask Array An array of cells to mask off from maze generation
options.open Array An array of objects designation what borders to open after generation
opions.start Object An object containing the x and y parameter of a cell to start maze generation from.

Example (generate)

maze.generate();

Example (mask)

let spec = {
   mask: [
     { c: 2, r: 3 },
     { c: 2, r: 4 }
   ]
};
mazeGenerator.generate(spec);

Example (start and mask)

let spec = {
   start: { c: 3, r: 3 },
   mask: [
     { c: 0, r: 0 },
     { c: 0, r: 1 },
     { c: 1, r: 0 },
     { c: 1, r: 1 }
   ]
};
mazeGenerator.generate(spec);

maze-generator-core-factory

A factory for generating maze generator core objects

maze-generator-core-factory.create(options) ⇒ maze-generator-core

Factory method that returns a maze generator core object. It takes one spec parameter that must be an object with named parameters.

Kind: static method of maze-generator-core-factory

Param Type Description
options Object Named parameters for generating a maze generator core
options.grid grid Grid based on @mitchallen/connection-grid-core

Example (Creating a maze-generator-core)

var cgFactory = require("@mitchallen/connection-grid-square"),
    mazeCore = require("@mitchallen/maze-generator-core"),
    connectionGrid = cgFactory.create( { x: 5, y: 6 } );
    maze = mazeCore.create( {
         grid: connectionGrid,
    });

@mitchallen/connection-grid-core

Connection Grid Core

Kind: global external
See: @mitchallen/connection-grid-core


Testing

To test, go to the root folder and type (sans $):

$ npm test

Repo(s)


Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.


Version History

Version 0.1.7

  • updated dependencies
  • updated client example

Version 0.1.6

  • changed openBorder to afterGenerate to make it more generic
  • integrated travis-ci and codecov.io
  • changed license to MIT
  • updated test cases for 100% code coverage

Version 0.1.5

  • added openBorder placeholder method for derived classes
  • updated documentation

Version 0.1.4

  • refactored generate method

Version 0.1.3

  • updated browser example

Version 0.1.2

  • removed file that wasn't being used.

Version 0.1.1

  • updated browser example to log array

Version 0.1.0

  • initial release