match-three-engine
v1.0.3
Published
The module is designed for quickly creating Match-3 game mechanics as backend
Readme
Match-3 Engine
The module is designed for quickly creating Match-3 game mechanics as backend. You can specify the number of gems in width, height, and their types. It works with a one-dimensional array internally.
Limitation: only rectangular boards can be created.
Usage:
// create engine
const engine = new Engine({
horizontal: 9,
vertical: 9,
types: ['red', 'green', 'blue', 'yellow', 'violet']
})
// for example width of array 7
for (let h in Array(engine.height).fill(0).map((i, idx)=>idx)) {
for (let w in Array(engine.width).fill(0).map((i, idx)=>idx)) {
const idx = h * engine.width + w
type = engine.board[idx]
// add sprite of type...
}
}
// recieve pointer event on sprites with indices fromIdx and toIdx
const matches = engine.swap(fromIdx, toIdx)
if (matches.length) {
// processing successed turn
} else {
// cancel turn
}
// in processing of successed turn remove matches and add new random gems
engine.removeAndAdd(matches)
// ...and may calculate scores
engine.calcScores(matches)For developement
npm i
# change `engine.coffee`
npm run build