This is a documentation for Board Game Arena: play board games online !
Your game state machine: states.inc.php: Porovnání verzí
(→Syntax) |
|||
Řádek 38: | Řádek 38: | ||
== Syntax == | == Syntax == | ||
=== | === id === | ||
The keys determine game states IDs (in the example above: 1 and 2). | The keys determine game states IDs (in the example above: 1 and 2). | ||
Řádek 48: | Řádek 48: | ||
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it). | ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it). | ||
=== | === name === | ||
(mandatory) | (mandatory) | ||
Řádek 82: | Řádek 82: | ||
break; | break; | ||
</pre> | </pre> | ||
== description == | |||
(mandatory) | |||
The description is the string that is displayed in the main action bar (top of the screen) when the state is active. | |||
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side: | |||
<pre> | |||
"description" => clienttranslate('${actplayer} must play a card or pass'), | |||
</pre> | |||
In the description string, you can use ${actplayer} to refer to the active player. | |||
You can also use custom arguments in your description. These custom arguments correspond to values returned by your "arg" PHP method (see below "arg" field). | |||
Example of custom field: | |||
<pre> | |||
In states.inc.php: | |||
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'), | |||
"arg" => "argMyArgumentMethod" | |||
In mygame.game.php: | |||
function argMyArgumentMethod() | |||
{ | |||
return array( | |||
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2" | |||
); | |||
} | |||
</pre> | |||
Note: You may specify an empty string ("") here if it never happens that the game remains in this state (ie: if this state immediately jump to another state when activated). | |||
Note²: Usually, you specify a string for "activeplayer" and "multipleactiveplayer" game states, and you specify an empty string for "game" game states. BUT, if you are using synchronous notifications, the client can remains few seconds on a "game" type game state, and in this case this may be useful to display a description in the status bar during this state. | |||
== descriptionmyturn == |
Verze z 11. 1. 2013, 14:39
This file describes the game states machine of your game (all the game states properties, and the transitions to get from one state to another).
Important: to understand the game state machine, the best is to read this presentation first:
Focus on BGA game state machine
Overall structure
The machine states is described by a PHP associative array.
Example:
$machinestates = array( // The initial state. Please do not modify. 1 => array( "name" => "gameSetup", "description" => clienttranslate("Game setup"), "type" => "manager", "action" => "stGameSetup", "transitions" => array( "" => 2 ) ), // Note: ID=2 => your first state 2 => array( "name" => "playerTurn", "description" => clienttranslate('${actplayer} must play a card or pass'), "descriptionmyturn" => clienttranslate('${you} must play a card or pass'), "type" => "activeplayer", "possibleactions" => array( "playCard", "pass" ), "transitions" => array( "playCard" => 2, "pass" => 2 ) ),
Syntax
id
The keys determine game states IDs (in the example above: 1 and 2).
IDs must be positive integers.
ID=1 is reserved for the first game state and should not be used (and you must not modify it).
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).
name
(mandatory)
The name of a game state is used to identify it in your game logic.
Several game states can share the same name, however this is not recommended.
PHP example:
// Get current game state $state = $this->gamestate->state(); if( $state['name'] == 'myGameState' ) { ... }
JS example:
onEnteringState: function( stateName, args ) { console.log( 'Entering state: '+stateName ); switch( stateName ) case 'myGameState': // Do some stuff at the beginning at this game state .... break;
description
(mandatory)
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:
"description" => clienttranslate('${actplayer} must play a card or pass'),
In the description string, you can use ${actplayer} to refer to the active player.
You can also use custom arguments in your description. These custom arguments correspond to values returned by your "arg" PHP method (see below "arg" field).
Example of custom field:
In states.inc.php: "description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'), "arg" => "argMyArgumentMethod" In mygame.game.php: function argMyArgumentMethod() { return array( 'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2" ); }
Note: You may specify an empty string ("") here if it never happens that the game remains in this state (ie: if this state immediately jump to another state when activated).
Note²: Usually, you specify a string for "activeplayer" and "multipleactiveplayer" game states, and you specify an empty string for "game" game states. BUT, if you are using synchronous notifications, the client can remains few seconds on a "game" type game state, and in this case this may be useful to display a description in the status bar during this state.