HTML5 Turn-based Game

By integrating with CelerX HTML5 Turn-based Game SDK, you can enable interactive multi-player competitions for your HTML5 turn-based games such as Chess and Gomoku.

NOTE: Before integrating with CelerX Game SDK, please make sure that your game does not contain any remotely-fetched resources otherwise your game may not be properly loaded. All game resources must be loaded from local resources.

API Overview

celerx.ready()

Tell the CelerX app that the game UI is ready to be displayed

Best practice: choose the right moment to call celerx.ready() to display your game UI. At the beginning, the game usually has a loading period. If you do not feel comfortable showing the game UI to the user too early, you can wait till everything is rendered, then call celerx.ready(). This way, you do not need to implement a loading screen yourself, the “confirm ready” UI in CelerX mobile app will cover this “ugly” loading process for you.

Attention: celerx.ready() is only for loading necessary resources and preparing a “ready to go” UI before the game starts. Do not trigger any game start logic automatically in celerx.ready(). At this stage, the game should wait for the CelerX mobile app to trigger the game start logic in celerx.onStart(function()).

celerx.onStart(function())

  • function() is the callback function in your game code

Put your game start logic in the callback function and pass it as a parameter in celerx.onStart(function()). The CelerX mobile app will trigger your callback function when both players are ready to go.

celerx.getMatch()

Get the current match information, the result is a json object

celerx.getMatch()

Returned json example:

celerx.getMatch();

Returned json example:

{  
   "matchId":"58702eb0-f5d2-4efa-9fca-9e31ca21a8cf",
   "sharedRandomSeed":0.173629058,
   "shouldLaunchTutorial":true,
   "forceMute":false,
   "currentPlayer":{  
        "index":1,
        "id":"ali23",
        "name":"Alice"
   },
   "players":[  
      {  
        "index":1,
        "id":"ali23",
        "name":"Alice"
      },
      {  
         "index":2,
         "id":"bob98",
         "name":"Bob"
      }
   ]
}
  • matchId String

the current match id

  • sharedRandomSeed float

a float value between 0 and 1. You need to use sharedRandomSeed as the seed for any random number generation in your game that may affect the game result. All players in the same match will use the same random seed, which ensures competition fairness.

  • shouldLaunchTutorial boolean

a boolean value indicating whether in this match there is a tutorial for the user. If the value is true, it is usually the first time when user plays this game. You can add some tutorial UI in your game when the value is true. When the value is false, hide your tutorial UI.

  • forceMute boolean

a boolean value indicating whether user wants to force mute the game audio. If the value is true, it means user wants to play game without game audio. E.g.: user would like to listen to his own background music from device, while playing the game. You should mute game audio at the beginning of the game. When the value is false, you can play game sound as usual.

  • currentPlayer Json

the current player who is playing the game

  • name String

a String value which can be used to display the player's nick name

  • id String

a String value which can be used as a unique user identifier on the CelerX platform

  • index int

an integer value indicating whether the player is player 1 or player 2 (only used in turn-based games)

  • players JsonArray

a list of players in the current match

celerx.sendState(state)

send a match state from the current player to other players

  • state UInt8Array

a UInt8Array value representing a serialized match state that the current player needs to send to other players

celerx.onStateReceived(function(state))

  • function(state) callback function

Pass a callback function as parameter to receive the new game state from other players.

  • state UInt8Array a UInt8Array value representing a serialized match state that the current player has received

celerx.win(state)

If the game logic decides that the current player is the winner, call this to API to submit the result to CelerX platform

  • state UInt8Array

a UInt8Array value representing a serialized match state of the final match result

celerx.lose(state)

If the game logic decides that the current player is the loser, call this to API to submit the result to CelerX platform

  • state UInt8Array

a UInt8Array value representing a serialized match state of the final match result

celerx.draw(state)

If the game logic decides that the current match result is a tie, call this to API to submit the result to CelerX platform

  • state UInt8Array

a UInt8Array value representing a serialized match state of the final match result

Last updated