Javascript Match-3 Game Lib - Node.JS and Browser compatible
http://www.pixelrebirth.net/2014/10/06/a-new-plugin-for-matching-things/#more-208 https://www.scirra.com/forum/plugin-jmatch3_t116977
var grid = new jMatch3.Grid({ width: 6, height: 7, gravity: "down" });var piece = grid.getPiece({ x: 0, y: 0 });A piece has a void object by default, but you can change it with your own
piece.object = { type: "gem" };-Or revert to the void object
piece.clear();The void Object type is "empty"
You can log the grid with a map of symbols
grid.debug({ empty: "-", gem: "g" });You can get all current matches
var matches = grid.getMatches();Clear matches to transform all matching pieces object to void object
grid.clearMatches();Apply gravity to fall down your pieces
grid.applyGravity();/* * options: * - width (default 10) * - height (default 10) * - gravity (default false): "up", "right", "down", "left", or false */ var grid = new jMatch3.Grid({ width: 6, height: 7, gravity: "down" });Return if given coords are in the grid
grid.coordsInWorld({ x: 10, y: 10 }); // return falseReturn the piece from given coords
var piece = grid.getPiece({ x: 4, y: 4 });Return the piece neighbour of another piece from a given direction
var neighbour = grid.neighbourOf(piece, "left");Return a Hash of pieces by direction
// return { up: theUpPiece, down: theDownPiece, right: theRightPiece, left: theLeftPiece } var neighbours = grid.neighboursOf(piece);Execute a callback for each current match
grid.forEachMatch(function() { // Your scoring stuff });Return an array of matches or false
var matches = grid.getMatches();Return an Array of pieces
var row = grid.getRow(0);Return an Array of pieces
var column = grid.getColumn(0);Destroy all matches and update the grid
grid.clearMatches();Swap 2 pieces object
grid.swapPieces(piece1, piece2);Apply gravity to fall down your pieces and return an Array of falling pieces
var fallingPieces = grid.applyGravity();Log the current grid with symbols
grid.debug({ empty: "-", gem: "g" });Get last empty piece from an Array of pieces
var lastEmpty = jMatch3.Grid.getLastEmptyPiece(pieces);Private Class
/* * Params: * - grid * - x * - y */ new Piece(grid, 0, 0);Replace the piece object by a the void object
piece.clear();Return relatives coordinates to the piece
var relativeCoordinates = piece.relativeCoordinates("right", 1); // return { x: 1, y: 0 }Return neighbour of the piece from a given direction
var neighbour = piece.neighbour("right");Return a Hash of pieces by direction
// return { up: theUpPiece, down: theDownPiece, right: theRightPiece, left: theLeftPiece } var neighbours = piece.neighbours();Return an Array of direct Matching Neighbours
var matchingNeighbours = piece.matchingNeighbours();Return an Array of deep Matching Neighbours
var deepMatchingNeighbours = piece.deepMatchingNeighbours();