This is a documentation for Board Game Arena: play board games online !

Ero sivun ”Your game state machine: states.inc.php” versioiden välillä

Board Game Arenasta
Siirry navigaatioon Siirry hakuun
(Created page with " 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...")
 
Rivi 47: Rivi 47:


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).
=== Game state name ===
(mandatory)
The name of a game state is used to identify it in your game logic.
PHP example:
<pre>
// Get current game state
$state = $this->gamestate->state();
if( $state['name'] == 'myGameState' )
{
...
}
</pre>
JS example:
<pre>
        onEnteringState: function( stateName, args )
        {
            console.log( 'Entering state: '+stateName );
           
            switch( stateName )
            case 'myGameState':
           
                // Do some stuff at the beginning at this game state
                ....
               
                break;
</pre>

Versio 11. tammikuuta 2013 kello 14.24

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

Game state 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).

Game state name

(mandatory) The name of a game state is used to identify it in your game logic.

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;