Skip to content

Jocly API Object

Michel Gutierrez edited this page Apr 14, 2017 · 4 revisions

This is the top level application API access.

Method Description
listGames() Returns available games
createMatch() Creates a match to run
getGameConfig() Returns the configuration of a given game
Constant Description
PLAYER_A Represents player A, the one who plays the first move (i.e White at Chess)
PLAYER_B Represents player B, the one who plays the second move (i.e Black at Chess)
DRAW Indicates a tie between users

listGames()

Returns an object describing all available game types. The keys of the object are the game machine name, for instance classic-chess or brazilian-draughts, the corresponding value is an object with properties:

  • title: the human readable name of the game
  • summary: a short description of the game
  • thumbnail: the URL to an image representing the game. When using the API from a browser, the URL is absolute, when from node.js, it is relative to the games directory
  • module: the name of the module the game belongs to. Games are organized into modules that share a set of resources and generally some code. For instance in the Jocly repository, all Chess variants are implemented within the chessbase module

Example:

Jocly.listGames()
  .then( (games) => {
    for(let name in games) {
      let game = games[name];
      console.info(game.title+":",game.summary)
    }
  })

createMatch(gameName)

Creates an instance of the specified game.

  • gameName: the name of the game type. The list of all available game names can be obtained from a call to listGames()

Returns the created Match object.

Example:

Jocly.createMatch('classic-chess')
  .then( (match) => {
    // proceed with playing the match
  })

getGameConfig(gameName)

Returns the configuration of a given game.

  • gameName: the name of the game type. The list of all available game names can be obtained from a call to listGames()

Note that if you have an instance of a Match object, you can also get this game configuration from Match.getConfig(). Check Match.getConfig() for details about the returned configuration object.

Example:

Jocly.getGameConfig('classic-chess')
  .then( (config) => {
    console.info("Game configuration",config);
  })
Clone this wiki locally