Giter Site home page Giter Site logo

maze-generator's Introduction

maze-generator

Generate mazes for other games.


    var rows = 21;// it is always recommended that the rows and columns be odd, otherwise you have a wall of the end of which ever side is even.
    var cols = 41;
    var startPoints = 3;
    var endPoint = {x: cols * 0.5, rows * 0.5};
    var board = mazegen.generate({
        rows: rows,
        cols: cols
    });
    // synchronous call to get points that are available around outside points.
    // if you pass 2 for the first argument, then all points will be in 2 squares from the outside
    // 0 will make it be points that are on the edge.
    var availablePoints = board.getPointsFromEdge(0, [board.types.PATH], startPoints);
    // this can generate paths while the maze is going. It is async, so pass a callback.
    board.forcePath(availablePoints, endPoint, [board.types.WALL], function() {
        console.log(board.asString());// output to the console the rendered board.
    });


##methods

board.types - this will tell you what type of values can be in the list. PREFERRED is no longer used. board.asString() - this will output the board as a string of values. handy for console logging the value of the maze. board.cols - the number of columns in the board board.each(fn) - this will call the fn(r, c) for each item in the maze. It can be handy for rendering the maze. board.end - the point of the end of the maze or exit. board.findPath - given a start point and an end point it will try to find a way. If there isn't one it will return the path the got closest to the end. board.forcePath - given a list of available points it will make sure to clear just enough blocks to allow a way to get to the end point for each start point. board.getClosestAvailablePoint - given a point it will find a path point close to it if it is on a wall. board.getPointsFromEdge - given an offset it will move in that many squares from the edge and return all points that match the types in that line around the map. board.getValue - given the row and the column it will return the value in that part of the maze board.rows - the number of rows board.starts - this is only populated after calling forcePath. All paths forced will add those start points into this array.

maze-generator's People

Contributors

wesjones avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.