-
Notifications
You must be signed in to change notification settings - Fork 27
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 |
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 thechessbase
module
Example:
Jocly.listGames()
.then( (games) => {
for(let name in games) {
let game = games[name];
console.info(game.title+":",game.summary)
}
})
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 tolistGames()
Returns the created Match object.
Example:
Jocly.createMatch('classic-chess')
.then( (match) => {
// proceed with playing the match
})
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 tolistGames()
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);
})