TripleGame
Triple Game Engine
Parameters
aConfig: Config (=defaultConfig):
Returns
any this
Example
const {Game, TRIPLE_FIG} = require('triple-game)';
var game = new Game();
game.userMove(0,0);static
TripleGame.userMove
userMoveLet the player (user) place next figure to field (x,y)
Parameters
x: integer:y: integer:fig: integer:a optional figure to play
TripleGame.turn
turn(pos: Pos)Let the player (user) place next figure to field (pos)
Parameters
pos: Pos:
TripleGame.isLegalMove
isLegalMoveCheck if figure can be set on pos
Parameters
pos: Pos:board coordinatesfig: integer:figure to set on this field
Returns
any boolean
TripleGame.setConfig
setConfigset game configuration. board size, figure probability etc.
Parameters
newConfig: Config:
TripleGame.on
onSet event callback. For detaile @see "Game Events".
Example
// log game over
game.on('gameover', (e) => {console.log('GAME OVER')} );
// use 'all' for all events
game.on('all', (e) => {console.log('event:', e.name )} );TripleGame.toString
toStringReturn game as string
Returns
Example
console.log( new require('triple-game').Game().toString() );
0 1 2 3
-----------
0| 1 1
1| 4 1 1
2| 1
3|
next: 2 reserve: 0 score: 0 gold: 0GameState
GameState
Pos
Stores X,Y coordinates
Parameters
args: ...args:see #assign for optional parameter
Board
Game Board a 2 dimensional array to hold integers in each cell
Parameters
cols: integer:rows: integer:initial: type (=0):a interger or function to fill the board
instance
Board.prototype.get
get(col: integer, row: integer): integerParameters
col: integer:row: integer:
Returns
integer content of board cell
Board.prototype.set
set(col: integer, row: integer, val: integer)Parameters
col: integer:row: integer:val: integer:
Board.prototype.forEach
forEach(callback: function)iterate through all cells
Parameters
callback: function:( item, x, y)
Board.prototype.getHash
getHash(filter: function): ObjectParameters
filter: function:= function( {pos,value} ) { return boolean }
Returns
Object board as object {{pos: {x:0,y:0}, val: 1},..}
Board.prototype.getPosList
getPosList(value: type): ArrayParameters
value: type:integer or function(x,y)
Returns
Array array of Pos of cells contains value
Board.prototype.validPos
validPos(pos: Pos): BooleanParameters
pos: Pos:
Returns
Boolean true if pos is inside board dimensions
Board.prototype.neighbours
neighbours(pos: Pos): ArrayParameters
pos: Pos:
Returns
Array array of Pos with neigbour cells
Board.prototype.getCluster
getCluster(startPos: Pos, members: integer, exclusive: Boolean): ArrayCollect positions with neighbours of the same value
Parameters
Returns
Array array of Pos
TRIPLE_FIG
triple figure definitions
each figure (object or item) has an integer id. Use the symbols in TRIPLE_FIG.
Figure properties are in 'var figures'. use function figureProp() to retrieve figure property. Example: score = figureProp(TRIPLE_FIG.GRASS).score;
Example
Figure Id Definitions
EMPTY: 0,
GRASS: 1,
BUSH: 2,
TREE: 3,
HUT: 4,
HOUSE: 5,
MANSION: 6,
CASTLE: 7,
FLOATINGCASTLE: 8,
TRIPLECASTLE: 9,
ROCK: 20,
MOUNTAIN: 21,
ROBOT: 25,
CRYSTAL: 26,
BEAR: 30,
TOMB: 31,
NINJA: 32,
CHURCH: 40,
CATHEDRAL: 41,
TREASURE: 50,
BIGTREASURE: 51,