https://hu.doc.boardgamearena.com/api.php?action=feedcontributions&user=Sourisdudesert&feedformat=atomBoard Game Arena - Felhasználó közreműködései [hu]2024-03-28T11:32:02ZFelhasználó közreműködéseiMediaWiki 1.39.0https://hu.doc.boardgamearena.com/index.php?title=Board_Game_Arena_Klub&diff=545Board Game Arena Klub2013-06-10T20:19:29Z<p>Sourisdudesert: </p>
<hr />
<div>==Why can't you just have a standard donation system where I can choose any money amount ?==<br />
<br />
With this "club" system, we try to highlight players who supported this website recently or do so on a regular basis. Depending on the amount of your donation, you are a member of the club for a given period of time.<br />
<br />
Many websites are using a more classical approach with a simple "donation box". By experience, we know that these websites rely on just a few generous users. Board Game Arena chooses to set 3 fixed amounts for donations in order to rely on a bigger number of small donors.<br />
<br />
==Is it mandatory to join the club ?==<br />
<br />
Of course not.<br />
<br />
You can play for free without any limitation even if you are not a member of the club: Board Game Arena is a free service. Statistics are just an extra : you don't need statistics to play and have fun, don't you ? As a matter of fact, most players are not club members.<br />
<br />
==What is a beginner account ? http://en.boardgamearena.com/theme/img/accounttypes/beginner.gif ==<br />
<br />
When you join Board Game Arena, your get a "beginner account" (http://en.boardgamearena.com/theme/img/accounttypes/beginner.gif) for 30 days. This beginner account allow you to view your own ELO ranking (http://en.boardgamearena.com/theme/img/common/rank.png) for each game. After 30 days, your account becomes a standard '''non member''' account (http://en.boardgamearena.com/theme/img/accounttypes/free.gif).<br />
<br />
==What becomes of the money ?==<br />
<br />
Board Game Arena service is managed by a semi-professional team who needs money to make it run (in particular: hosting cost).<br />
<br />
Player donations are used to develop this website (new features, new games), to make it run (hosting, maintenance), to build the player community (events)...<br />
<br />
A big "thank you" to all members of the Board Game Arena Club whose contributions allow this website to exist for the enjoyment of everyone !</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=508Main game logic: yourgamename.game.php2013-01-11T16:03:04Z<p>Sourisdudesert: /* Game states and active players */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
Example:<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_score score FROM player WHERE player_id='$player_id'" );<br />
<br />
Result:<br />
array(<br />
'id'=>1234, 'name'=>'myuser0', 'score'=>1 <br />
)<br />
</pre><br />
<br />
; getNonEmptyObjectFromDB( $sql )<br />
: Idem than previous one, but raise an exception if no row is found<br />
<br />
; getObjectListFromDB( $sql, $bUniqueValue=false )<br />
: Return an array of rows for a sql SELECT query.<br />
: the result if the same than "getCollectionFromDB" except that the result is a simple array (and not an associative array).<br />
: The result can be empty.<br />
: If you specified $bUniqueValue=true and if your SQL query request 1 field, the method returns directly an array of values.<br />
<br />
Example 1:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
'myuser0',<br />
'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getDoubleKeyCollectionFromDB( $sql, $bSingleValue=false )<br />
: Return an associative array of associative array, from a SQL SELECT query.<br />
: First array level correspond to first column specified in SQL query.<br />
: Second array level correspond to second column specified in SQL query.<br />
: If bSingleValue = true, keep only third column on result<br />
<br />
<br />
; DbGetLastId()<br />
: Return the PRIMARY key of the last inserted row (see PHP mysql_insert_id function).<br />
<br />
; DbAffectedRow()<br />
: Return the number of row affected by the last operation<br />
<br />
; escapeStringForDB( $string )<br />
: You must use this function on every string type data in your database that contains unsafe data.<br />
: (unsafe = can be modified by a player).<br />
: This method makes sure that no SQL injection will be done through the string used.<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see Editing [[Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Use globals ==<br />
<br />
Sometimes, you have to keep a single integer value that is global to your game, and you don't want to create a DB table specifically for it.<br />
<br />
Using a BGA framework "global", you can do such a thing. Your value will be stored in the "global" table in database, and you can access it with simple methods.<br />
<br />
'''initGameStateLabels'''<br />
<br />
This method is located at the beginning of your game logic. This is the place you defines the globals used in your game logic, by assigning them IDs.<br />
<br />
You can define up to 89 globals, with IDs from 10 to 89. You must NOT use globals outside this range as globals are used by other components of the framework.<br />
<br />
<pre><br />
self::initGameStateLabels( array( <br />
"my_first_global_variable" => 10,<br />
"my_second_global_variable" => 11<br />
) );<br />
</pre><br />
<br />
'''setGameStateInitialValue( $value_label, $value_value )'''<br />
<br />
Init your global value. Must be called before any use of your global, so you should call this method from your "setupNewGame" method.<br />
<br />
'''getGameStateValue( $value_label )'''<br />
<br />
Retrieve the current value of a global.<br />
<br />
'''setGameStateValue( $value_label, $value_value )'''<br />
<br />
Set the current value of a global.<br />
<br />
'''incGameStateValue( $value_label, $increment )'''<br />
<br />
Increment the current value of a global. If increment is negative, decrement the value of the global.<br />
<br />
Return the final value of the global.<br />
<br />
== Game states and active players ==<br />
<br />
; checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: The action is valid if it is listed as a "possibleactions" in the current game state (see game state description).<br />
: This method should be called in the first place in ALL your PHP methods that handle players action, in order to make sure a player can't do an action when the rules disallow it at this moment of the game.<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception. This is useful when several actions are possible in order to test each of them without throwing exceptions.<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active in the natural player order.<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
; function activePrevPlayer()<br />
: Make the previous player active (in the natural player order).<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
== Players turn order ==<br />
<br />
'''createNextPlayerTable( $players, $bLoop=true )'''<br />
<br />
Return an associative array which associate each player with the next player around the table.<br />
<br />
In addition, key 0 is associated to the first player to play.<br />
<br />
Example: if three player with ID 1, 2 and 3 are around the table, in this order, the method returns:<br />
<pre><br />
$players = self::loadPlayersBasicInfos()<br />
$nextPlayers = createNextPlayerTable( $players ); // return array( 1 => 2, 2 => 3, 3 => 1, 0 => 1 );<br />
$nextPlayers = createNextPlayerTable( $players, false ); // return array( 1 => 2, 2 => 3, 0 => 1 );<br />
<br />
</pre><br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
See [[Translations]]<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=506Main game logic: yourgamename.game.php2013-01-11T15:58:07Z<p>Sourisdudesert: /* Using globals */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
Example:<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_score score FROM player WHERE player_id='$player_id'" );<br />
<br />
Result:<br />
array(<br />
'id'=>1234, 'name'=>'myuser0', 'score'=>1 <br />
)<br />
</pre><br />
<br />
; getNonEmptyObjectFromDB( $sql )<br />
: Idem than previous one, but raise an exception if no row is found<br />
<br />
; getObjectListFromDB( $sql, $bUniqueValue=false )<br />
: Return an array of rows for a sql SELECT query.<br />
: the result if the same than "getCollectionFromDB" except that the result is a simple array (and not an associative array).<br />
: The result can be empty.<br />
: If you specified $bUniqueValue=true and if your SQL query request 1 field, the method returns directly an array of values.<br />
<br />
Example 1:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
'myuser0',<br />
'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getDoubleKeyCollectionFromDB( $sql, $bSingleValue=false )<br />
: Return an associative array of associative array, from a SQL SELECT query.<br />
: First array level correspond to first column specified in SQL query.<br />
: Second array level correspond to second column specified in SQL query.<br />
: If bSingleValue = true, keep only third column on result<br />
<br />
<br />
; DbGetLastId()<br />
: Return the PRIMARY key of the last inserted row (see PHP mysql_insert_id function).<br />
<br />
; DbAffectedRow()<br />
: Return the number of row affected by the last operation<br />
<br />
; escapeStringForDB( $string )<br />
: You must use this function on every string type data in your database that contains unsafe data.<br />
: (unsafe = can be modified by a player).<br />
: This method makes sure that no SQL injection will be done through the string used.<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see Editing [[Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Use globals ==<br />
<br />
Sometimes, you have to keep a single integer value that is global to your game, and you don't want to create a DB table specifically for it.<br />
<br />
Using a BGA framework "global", you can do such a thing. Your value will be stored in the "global" table in database, and you can access it with simple methods.<br />
<br />
'''initGameStateLabels'''<br />
<br />
This method is located at the beginning of your game logic. This is the place you defines the globals used in your game logic, by assigning them IDs.<br />
<br />
You can define up to 89 globals, with IDs from 10 to 89. You must NOT use globals outside this range as globals are used by other components of the framework.<br />
<br />
<pre><br />
self::initGameStateLabels( array( <br />
"my_first_global_variable" => 10,<br />
"my_second_global_variable" => 11<br />
) );<br />
</pre><br />
<br />
'''setGameStateInitialValue( $value_label, $value_value )'''<br />
<br />
Init your global value. Must be called before any use of your global, so you should call this method from your "setupNewGame" method.<br />
<br />
'''getGameStateValue( $value_label )'''<br />
<br />
Retrieve the current value of a global.<br />
<br />
'''setGameStateValue( $value_label, $value_value )'''<br />
<br />
Set the current value of a global.<br />
<br />
'''incGameStateValue( $value_label, $increment )'''<br />
<br />
Increment the current value of a global. If increment is negative, decrement the value of the global.<br />
<br />
Return the final value of the global.<br />
<br />
== Game states and active players ==<br />
<br />
; checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: The action is valid if it is listed as a "possibleactions" in the current game state (see game state description).<br />
: This method should be called in the first place in ALL your PHP methods that handle players action, in order to make sure a player can't do an action when the rules disallow it at this moment of the game.<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception. This is useful when several actions are possible in order to test each of them without throwing exceptions.<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active in the natural player order.<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
; function activePrevPlayer()<br />
: Make the previous player active (in the natural player order).<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
See [[Translations]]<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=505Main game logic: yourgamename.game.php2013-01-11T15:49:19Z<p>Sourisdudesert: /* Accessing database */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
Example:<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_score score FROM player WHERE player_id='$player_id'" );<br />
<br />
Result:<br />
array(<br />
'id'=>1234, 'name'=>'myuser0', 'score'=>1 <br />
)<br />
</pre><br />
<br />
; getNonEmptyObjectFromDB( $sql )<br />
: Idem than previous one, but raise an exception if no row is found<br />
<br />
; getObjectListFromDB( $sql, $bUniqueValue=false )<br />
: Return an array of rows for a sql SELECT query.<br />
: the result if the same than "getCollectionFromDB" except that the result is a simple array (and not an associative array).<br />
: The result can be empty.<br />
: If you specified $bUniqueValue=true and if your SQL query request 1 field, the method returns directly an array of values.<br />
<br />
Example 1:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
'myuser0',<br />
'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getDoubleKeyCollectionFromDB( $sql, $bSingleValue=false )<br />
: Return an associative array of associative array, from a SQL SELECT query.<br />
: First array level correspond to first column specified in SQL query.<br />
: Second array level correspond to second column specified in SQL query.<br />
: If bSingleValue = true, keep only third column on result<br />
<br />
<br />
; DbGetLastId()<br />
: Return the PRIMARY key of the last inserted row (see PHP mysql_insert_id function).<br />
<br />
; DbAffectedRow()<br />
: Return the number of row affected by the last operation<br />
<br />
; escapeStringForDB( $string )<br />
: You must use this function on every string type data in your database that contains unsafe data.<br />
: (unsafe = can be modified by a player).<br />
: This method makes sure that no SQL injection will be done through the string used.<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see Editing [[Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Using globals ==<br />
<br />
== Game states and active players ==<br />
<br />
; checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: The action is valid if it is listed as a "possibleactions" in the current game state (see game state description).<br />
: This method should be called in the first place in ALL your PHP methods that handle players action, in order to make sure a player can't do an action when the rules disallow it at this moment of the game.<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception. This is useful when several actions are possible in order to test each of them without throwing exceptions.<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active in the natural player order.<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
; function activePrevPlayer()<br />
: Make the previous player active (in the natural player order).<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
See [[Translations]]<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=504Main game logic: yourgamename.game.php2013-01-11T15:47:57Z<p>Sourisdudesert: /* Translations */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
Example:<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_score score FROM player WHERE player_id='$player_id'" );<br />
<br />
Result:<br />
array(<br />
'id'=>1234, 'name'=>'myuser0', 'score'=>1 <br />
)<br />
</pre><br />
<br />
; getNonEmptyObjectFromDB( $sql )<br />
: Idem than previous one, but raise an exception if no row is found<br />
<br />
; getObjectListFromDB( $sql, $bUniqueValue=false )<br />
: Return an array of rows for a sql SELECT query.<br />
: the result if the same than "getCollectionFromDB" except that the result is a simple array (and not an associative array).<br />
: The result can be empty.<br />
: If you specified $bUniqueValue=true and if your SQL query request 1 field, the method returns directly an array of values.<br />
<br />
Example 1:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
'myuser0',<br />
'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getDoubleKeyCollectionFromDB( $sql, $bSingleValue=false )<br />
: Return an associative array of associative array, from a SQL SELECT query.<br />
: First array level correspond to first column specified in SQL query.<br />
: Second array level correspond to second column specified in SQL query.<br />
: If bSingleValue = true, keep only third column on result<br />
<br />
<br />
; DbGetLastId()<br />
: Return the PRIMARY key of the last inserted row (see PHP mysql_insert_id function).<br />
<br />
; DbAffectedRow()<br />
: Return the number of row affected by the last operation<br />
<br />
; escapeStringForDB( $string )<br />
: You must use this function on every string type data in your database that contains unsafe data.<br />
: (unsafe = can be modified by a player).<br />
: This method makes sure that no SQL injection will be done through the string used.<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see Editing [[Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: The action is valid if it is listed as a "possibleactions" in the current game state (see game state description).<br />
: This method should be called in the first place in ALL your PHP methods that handle players action, in order to make sure a player can't do an action when the rules disallow it at this moment of the game.<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception. This is useful when several actions are possible in order to test each of them without throwing exceptions.<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active in the natural player order.<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
; function activePrevPlayer()<br />
: Make the previous player active (in the natural player order).<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
See [[Translations]]<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Translations&diff=503Translations2013-01-11T15:47:46Z<p>Sourisdudesert: </p>
<hr />
<div><br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Translations&diff=502Translations2013-01-11T15:47:33Z<p>Sourisdudesert: Created page with " (todo)"</p>
<hr />
<div><br />
(todo)</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Studio&diff=501Studio2013-01-11T15:47:24Z<p>Sourisdudesert: /* Other components */</p>
<hr />
<div>[[File:Bga_studio_small.jpg]]<br />
<br />
Note: Please DO NOT translate Studio Documentation, so that there can be one place where you can find the last information available.<br />
<br />
== What is Board Game Arena Studio? ==<br />
<br />
'''Board Game Arena Studio''' is a platform to build online board game adaptation using the Board Game Arena platform.<br />
<br />
It is open to any gamer with development skills :)<br />
<br />
See announcement here:<br />
http://forum.boardgamearena.com/viewtopic.php?f=10&t=1973<br />
<br />
== Discover BGA Studio in 5 presentations ==<br />
<br />
Why, how, what... to start discovering BGA Studio, we prepare you 5 "powerpoint" presentations:<br />
<br />
* [http://www.slideshare.net/boardgamearena/5-reasons-why-you-should-use-bga-studio-for-your-online-board-game 5 reasons why you should use BGA Studio for your online board game]<br />
* [http://www.slideshare.net/boardgamearena/the-8-steps-to-create-a-board-game-on-board-game-arena The 8 steps to create a board game on Board Game Arena]<br />
* [http://www.slideshare.net/boardgamearena/the-bga-framework-at-a-glance The BGA Framework at a glance]<br />
* [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
* [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines]<br />
<br />
== How to join BGA developer team? ==<br />
<br />
Please see: [[How to join BGA developer team?]]<br />
<br />
== Great, I'm in! ... How should I start? ==<br />
<br />
If you didn't already, check the presentations at the top of this page to get the basics.<br />
<br />
After that, we would advise you to take a peek at one or both of these two game creation tutorials:<br />
* [[Tutorial reversi]]<br />
* [[Tutorial gomoku]]<br />
<br />
Then start editing files and see what happens! ;)<br />
<br />
If you have any questions, please ask them on the [http://forum.boardgamearena.com/viewforum.php?f=12 development forum].<br />
<br />
== BGA Studio documentation ==<br />
<br />
[[Studio FAQ]]<br />
<br />
=== BGA Studio Framework reference ===<br />
<br />
This part of the documentation focus on the development framework itself: functions and methods available to build your game.<br />
<br />
[[Studio file reference|File structure of a BGA game]]<br />
<br />
==== Game logic ====<br />
<br />
* [[Main game logic: yourgamename.game.php]]<br />
* [[Your game state machine: states.inc.php]]<br />
* [[Game database model: dbmodel.sql]]<br />
* [[Players actions: yourgamename.action.php]]<br />
* [[Game material description: material.inc.php]]<br />
* [[Game statistics: stats.inc.php]]<br />
<br />
==== Game interface ====<br />
<br />
* [[Game interface logic: yourgamename.js]]<br />
* [[Game art: img directory]]<br />
* [[Game interface stylesheet: yourgamename.css]]<br />
* [[Game layout: view and template: yourgamename.view.php and yourgamename_yourgamename.tpl]]<br />
<br />
==== Other components ====<br />
<br />
* [[Translations]] (how to make your game translatable)<br />
* [[Game options and preferences: gameoptions.inc.php]]<br />
<br />
=== BGA Studio game components reference ===<br />
<br />
Game components are useful tools you can use in your game adaptations.<br />
<br />
* [[Deck]]: a PHP component to manage cards (deck, hands, picking cards, moving cards, shuffle deck, ...).<br />
* [[Counter]]: a JS component to manage a counter that can increase/decrease (ex: player's score).<br />
* [[Draggable]]: a JS component to manage drag'n'drop actions.<br />
* [[ExpandableSection]]: a JS component to manage a rectangular block of HTML than can be displayed/hide.<br />
* [[Scrollmap]]: a JS component to manage a scrollable game area (useful when the game area can be infinite. Examples: Saboteur or Takenoko games).<br />
* [[Stock]]: a JS component to manage and display a set of game elements displayed at a position.<br />
* [[Wrapper]]: a JS component to wrap a <div> element around his child, even if these elements are absolute positioned.<br />
* [[Zone]]: a JS component to manage a zone of the board where several game elements can come and leave, but should be well displayed together (See for example: token's places at Can't Stop).<br />
<br />
=== BGA Studio user guide ===<br />
<br />
This part of the documentation is a user guide for the BGA Studio online development environment.<br />
<br />
[[Studio back-office]]<br />
<br />
== Other resources ==<br />
<br />
[http://forum.boardgamearena.com/viewforum.php?f=12 Development forum]<br />
<br />
[http://forum.boardgamearena.com/viewforum.php?f=4 Bugs forum]</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=500Main game logic: yourgamename.game.php2013-01-11T15:44:56Z<p>Sourisdudesert: /* Game states and active players */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
Example:<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_score score FROM player WHERE player_id='$player_id'" );<br />
<br />
Result:<br />
array(<br />
'id'=>1234, 'name'=>'myuser0', 'score'=>1 <br />
)<br />
</pre><br />
<br />
; getNonEmptyObjectFromDB( $sql )<br />
: Idem than previous one, but raise an exception if no row is found<br />
<br />
; getObjectListFromDB( $sql, $bUniqueValue=false )<br />
: Return an array of rows for a sql SELECT query.<br />
: the result if the same than "getCollectionFromDB" except that the result is a simple array (and not an associative array).<br />
: The result can be empty.<br />
: If you specified $bUniqueValue=true and if your SQL query request 1 field, the method returns directly an array of values.<br />
<br />
Example 1:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
'myuser0',<br />
'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getDoubleKeyCollectionFromDB( $sql, $bSingleValue=false )<br />
: Return an associative array of associative array, from a SQL SELECT query.<br />
: First array level correspond to first column specified in SQL query.<br />
: Second array level correspond to second column specified in SQL query.<br />
: If bSingleValue = true, keep only third column on result<br />
<br />
<br />
; DbGetLastId()<br />
: Return the PRIMARY key of the last inserted row (see PHP mysql_insert_id function).<br />
<br />
; DbAffectedRow()<br />
: Return the number of row affected by the last operation<br />
<br />
; escapeStringForDB( $string )<br />
: You must use this function on every string type data in your database that contains unsafe data.<br />
: (unsafe = can be modified by a player).<br />
: This method makes sure that no SQL injection will be done through the string used.<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see Editing [[Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: The action is valid if it is listed as a "possibleactions" in the current game state (see game state description).<br />
: This method should be called in the first place in ALL your PHP methods that handle players action, in order to make sure a player can't do an action when the rules disallow it at this moment of the game.<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception. This is useful when several actions are possible in order to test each of them without throwing exceptions.<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active in the natural player order.<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
; function activePrevPlayer()<br />
: Make the previous player active (in the natural player order).<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=499Main game logic: yourgamename.game.php2013-01-11T15:42:31Z<p>Sourisdudesert: /* Accessing database */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
Example:<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_score score FROM player WHERE player_id='$player_id'" );<br />
<br />
Result:<br />
array(<br />
'id'=>1234, 'name'=>'myuser0', 'score'=>1 <br />
)<br />
</pre><br />
<br />
; getNonEmptyObjectFromDB( $sql )<br />
: Idem than previous one, but raise an exception if no row is found<br />
<br />
; getObjectListFromDB( $sql, $bUniqueValue=false )<br />
: Return an array of rows for a sql SELECT query.<br />
: the result if the same than "getCollectionFromDB" except that the result is a simple array (and not an associative array).<br />
: The result can be empty.<br />
: If you specified $bUniqueValue=true and if your SQL query request 1 field, the method returns directly an array of values.<br />
<br />
Example 1:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getObjectListFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
'myuser0',<br />
'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getDoubleKeyCollectionFromDB( $sql, $bSingleValue=false )<br />
: Return an associative array of associative array, from a SQL SELECT query.<br />
: First array level correspond to first column specified in SQL query.<br />
: Second array level correspond to second column specified in SQL query.<br />
: If bSingleValue = true, keep only third column on result<br />
<br />
<br />
; DbGetLastId()<br />
: Return the PRIMARY key of the last inserted row (see PHP mysql_insert_id function).<br />
<br />
; DbAffectedRow()<br />
: Return the number of row affected by the last operation<br />
<br />
; escapeStringForDB( $string )<br />
: You must use this function on every string type data in your database that contains unsafe data.<br />
: (unsafe = can be modified by a player).<br />
: This method makes sure that no SQL injection will be done through the string used.<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see Editing [[Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: The action is valid if it is listed as a "possibleactions" in the current game state (see game state description).<br />
: This method should be called in the first place in ALL your PHP methods that handle players action, in order to make sure a player can't do an action when the rules disallow it at this moment of the game.<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active in the natural player order.<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
; function activePrevPlayer()<br />
: Make the previous player active (in the natural player order).<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=498Main game logic: yourgamename.game.php2013-01-11T15:33:44Z<p>Sourisdudesert: /* Accessing database */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
Example:<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_score score FROM player WHERE player_id='$player_id'" );<br />
<br />
Result:<br />
array(<br />
'id'=>1234, 'name'=>'myuser0', 'score'=>1 <br />
)<br />
</pre><br />
<br />
; function DbGetLastId()<br />
: Return the PRIMARY key of the last inserted row (see PHP mysql_insert_id function).<br />
<br />
; function DbAffectedRow()<br />
: Return the number of row affected by the last operation<br />
<br />
; function escapeStringForDB( $string )<br />
: You must use this function on every string type data in your database that contains unsafe data.<br />
: (unsafe = can be modified by a player).<br />
: This method makes sure that no SQL injection will be done through the string used.<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see Editing [[Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: The action is valid if it is listed as a "possibleactions" in the current game state (see game state description).<br />
: This method should be called in the first place in ALL your PHP methods that handle players action, in order to make sure a player can't do an action when the rules disallow it at this moment of the game.<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active in the natural player order.<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
; function activePrevPlayer()<br />
: Make the previous player active (in the natural player order).<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Game_material_description:_material.inc.php&diff=497Game material description: material.inc.php2013-01-11T15:23:52Z<p>Sourisdudesert: </p>
<hr />
<div>This PHP file describes all the material of your game.<br />
<br />
This file is include by the constructor of your main game logic (yourgame.game.php), and then the variables defined here are accessible everywhere in your game logic file.<br />
<br />
Using material.inc.php makes your PHP logic file smaller and clean.<br />
<br />
Example from "Hearts": if you define this in material.inc.php:<br />
<br />
<pre><br />
$this->colors = array(<br />
1 => array( 'name' => clienttranslate('spade'),<br />
'nametr' => self::_('spade') ),<br />
2 => array( 'name' => clienttranslate('heart'),<br />
'nametr' => self::_('heart') ),<br />
3 => array( 'name' => clienttranslate('club'),<br />
'nametr' => self::_('club') ),<br />
4 => array( 'name' => clienttranslate('diamond'),<br />
'nametr' => self::_('diamond') )<br />
);<br />
</pre><br />
<br />
... you can access "$this->colors" everywhere in your PHP game logic file.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Game_material_description:_material.inc.php&diff=496Game material description: material.inc.php2013-01-11T15:18:46Z<p>Sourisdudesert: Created page with "This PHP file describes all the material of your game. This file is include by the constructor of your main game logic (yourgame.game.php), and then the variables defined her..."</p>
<hr />
<div>This PHP file describes all the material of your game.<br />
<br />
This file is include by the constructor of your main game logic (yourgame.game.php), and then the variables defined here are accessible everywhere in your game logic file.<br />
<br />
Example from "Hearts": if you define this in material.inc.php:<br />
<br />
<pre><br />
$this->colors = array(<br />
1 => array( 'name' => clienttranslate('spade'),<br />
'nametr' => self::_('spade') ),<br />
2 => array( 'name' => clienttranslate('heart'),<br />
'nametr' => self::_('heart') ),<br />
3 => array( 'name' => clienttranslate('club'),<br />
'nametr' => self::_('club') ),<br />
4 => array( 'name' => clienttranslate('diamond'),<br />
'nametr' => self::_('diamond') )<br />
);<br />
</pre><br />
<br />
... you can access "$this->colors" everywhere in your PHP game logic file.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Players_actions:_yourgamename.action.php&diff=495Players actions: yourgamename.action.php2013-01-11T15:07:01Z<p>Sourisdudesert: /* Methods to use in action methods */</p>
<hr />
<div><br />
== Purpose of this file ==<br />
<br />
With this file, you define all the players entry points (ie: possible game actions) of your game.<br />
<br />
This file is a sort of "bridge" between the AJAX calls you are doing from your Javascript client side, and your main PHP code in "yourgame.game.php".<br />
<br />
The role of the methods defined in this file is to filter the arguments, eventually to format them a little bit, and then to call a corresponding PHP method from your main game logic ("yourgame.game.php" file).<br />
<br />
Methods in this file must be short: no game logic must be introduced here.<br />
<br />
== Example of typical action method ==<br />
<br />
(from Reversi example)<br />
<br />
<pre><br />
public function playDisc()<br />
{<br />
self::setAjaxMode(); <br />
$x = self::getArg( "x", AT_posint, true );<br />
$y = self::getArg( "y", AT_posint, true );<br />
$result = $this->game->playDisc( $x, $y );<br />
self::ajaxResponse( );<br />
}<br />
</pre><br />
<br />
== Methods to use in action methods ==<br />
<br />
'''function setAjaxMode'''<br />
<br />
Must be use at the beginning of each action method.<br />
<br />
'''function ajaxResponse'''<br />
<br />
Must be use at the end of each action method.<br />
<br />
'''function getArg( $argName, $argType, $mandatory=false, $default=NULL, $argTypeDetails=array(), $bCanFail=false )'''<br />
<br />
This method must be used to retrieve the arguments sent with your AJAX query.<br />
You must NOT use "_GET", "_POST" or equivalent PHP variables to do this, as it is unsafe.<br />
This method use the following arguments:<br />
* argName: the name of the argument to retrieve.<br />
* argType: the type of the argument. You should use one of the following:<br />
'AT_int' for an integer<br />
'AT_posint' for a positive integer <br />
'AT_float' for a float<br />
'AT_bool' for 1/0/true/false<br />
'AT_enum' for an enumeration (argTypeDetails list the possible values as an array)<br />
'AT_alphanum' for a string with 0-9a-zA-Z_ and space<br />
'AT_numberlist' for a list of several numbers separated with "," or ";" (ex: exemple: 1,4;2,3;-1,2).<br />
* mandatory: specify "true" if the argument is mandatory.<br />
* default: if mandatory=false, you can specify here a default value in case the argument is not present.<br />
* argTypeDetails: see AT_enum above.<br />
* bCanFail: if true, specify that it may be possible that the argument won't be of the type specified by argType (and then do not log this as a fatal error in the system, and return a standard exception to the player).<br />
<br />
<br />
'''function isArg( $argName )'''<br />
<br />
This is a useful method when you only want to check if an argument is present or not present in your AJAX request (and don't care of the value.<br />
<br />
It returns "true" or "false" whether "argName" has been specified as an argument of the AJAX request or not.<br />
<br />
== Useful tip: retrieve a list of number ==<br />
<br />
If your Javascript send a list of integer separated by ";" (ex: "1;2;3;4") as an argument, you can transform them in a PHP array with the following:<br />
<br />
<pre><br />
public function playCards()<br />
{<br />
self::setAjaxMode(); <br />
<br />
$card_ids_raw = self::getArg( "card_ids", AT_numberlist, true );<br />
<br />
// Removing last ';' if exists<br />
if( substr( $card_ids_raw, -1 ) == ';' )<br />
$card_ids_raw = substr( $card_ids_raw, 0, -1 );<br />
if( $card_ids_raw == '' )<br />
$card_ids = array();<br />
else<br />
$card_ids = explode( ';', $card_ids_raw );<br />
<br />
$this->game->playCards( $card_ids );<br />
self::ajaxResponse( );<br />
}<br />
</pre></div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Players_actions:_yourgamename.action.php&diff=494Players actions: yourgamename.action.php2013-01-11T15:03:50Z<p>Sourisdudesert: /* Methods to use in action methods */</p>
<hr />
<div><br />
== Purpose of this file ==<br />
<br />
With this file, you define all the players entry points (ie: possible game actions) of your game.<br />
<br />
This file is a sort of "bridge" between the AJAX calls you are doing from your Javascript client side, and your main PHP code in "yourgame.game.php".<br />
<br />
The role of the methods defined in this file is to filter the arguments, eventually to format them a little bit, and then to call a corresponding PHP method from your main game logic ("yourgame.game.php" file).<br />
<br />
Methods in this file must be short: no game logic must be introduced here.<br />
<br />
== Example of typical action method ==<br />
<br />
(from Reversi example)<br />
<br />
<pre><br />
public function playDisc()<br />
{<br />
self::setAjaxMode(); <br />
$x = self::getArg( "x", AT_posint, true );<br />
$y = self::getArg( "y", AT_posint, true );<br />
$result = $this->game->playDisc( $x, $y );<br />
self::ajaxResponse( );<br />
}<br />
</pre><br />
<br />
== Methods to use in action methods ==<br />
<br />
'''function setAjaxMode'''<br />
<br />
Must be use at the beginning of each action method.<br />
<br />
'''function ajaxResponse'''<br />
<br />
Must be use at the end of each action method.<br />
<br />
'''function getArg( $argName, $argType, $mandatory=false, $default=NULL, $argTypeDetails=array(), $bCanFail=false )'''<br />
<br />
This method must be used to retrieve the arguments sent with your AJAX query.<br />
You must NOT use "_GET", "_POST" or equivalent PHP variables to do this, as it is unsafe.<br />
This method use the following arguments:<br />
* argName: the name of the argument to retrieve.<br />
* argType: the type of the argument. You should use one of the following:<br />
'AT_int' for an integer<br />
'AT_posint' for a positive integer <br />
'AT_float' for a float<br />
'AT_bool' for 1/0/true/false<br />
'AT_enum' for an enumeration (argTypeDetails list the possible values as an array)<br />
'AT_alphanum' for a string with 0-9a-zA-Z_ and space<br />
'AT_numberlist' for a list of several numbers separated with "," or ";" (ex: exemple: 1,4;2,3;-1,2).<br />
* mandatory: specify "true" if the argument is mandatory.<br />
* default: if mandatory=false, you can specify here a default value in case the argument is not present.<br />
* argTypeDetails: see AT_enum above.<br />
* bCanFail: if true, specify that it may be possible that the argument won't be of the type specified by argType (and then do not log this as a fatal error in the system, and return a standard exception to the player).<br />
<br />
<br />
'''function isArg( $argName )'''<br />
<br />
This is a useful method when you only want to check if an argument is present or not present in your AJAX request (and don't care of the value.<br />
<br />
It returns "true" or "false" whether "argName" has been specified as an argument of the AJAX request or not.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Players_actions:_yourgamename.action.php&diff=493Players actions: yourgamename.action.php2013-01-11T14:58:20Z<p>Sourisdudesert: /* Methods to use in action methods */</p>
<hr />
<div><br />
== Purpose of this file ==<br />
<br />
With this file, you define all the players entry points (ie: possible game actions) of your game.<br />
<br />
This file is a sort of "bridge" between the AJAX calls you are doing from your Javascript client side, and your main PHP code in "yourgame.game.php".<br />
<br />
The role of the methods defined in this file is to filter the arguments, eventually to format them a little bit, and then to call a corresponding PHP method from your main game logic ("yourgame.game.php" file).<br />
<br />
Methods in this file must be short: no game logic must be introduced here.<br />
<br />
== Example of typical action method ==<br />
<br />
(from Reversi example)<br />
<br />
<pre><br />
public function playDisc()<br />
{<br />
self::setAjaxMode(); <br />
$x = self::getArg( "x", AT_posint, true );<br />
$y = self::getArg( "y", AT_posint, true );<br />
$result = $this->game->playDisc( $x, $y );<br />
self::ajaxResponse( );<br />
}<br />
</pre><br />
<br />
== Methods to use in action methods ==<br />
<br />
'''function setAjaxMode'''<br />
<br />
Must be use at the beginning of each action method.<br />
<br />
'''function ajaxResponse'''<br />
<br />
Must be use at the end of each action method.<br />
<br />
'''function getArg( $argName, $argType, $mandatory=false, $default=NULL, $argTypeDetails=array(), $bCanFail=false )'''<br />
<br />
This method must be used to retrieve the arguments sent with your AJAX query.<br />
You must NOT use "_GET", "_POST" or equivalent PHP variables to do this, as it is unsafe.<br />
This method use the following arguments:<br />
* argName: the name of the argument to retrieve.<br />
* argType: the type of the argument. You should use one of the following:<br />
'AT_int' for an integer<br />
'AT_posint' for a positive integer <br />
'AT_float' for a float<br />
'AT_bool' for 1/0/true/false<br />
'AT_enum' for an enumeration (argTypeDetails list the possible values as an array)<br />
'AT_alphanum' for a string with 0-9a-zA-Z_ and space<br />
'AT_numberlist' for a list of several numbers separated with "," or ";" (ex: exemple: 1,4;2,3;-1,2).<br />
<br />
<br />
bCanFail means than a validation failure is possible (user input)<br />
The main argType values are as follows.<br />
<br />
<br />
<br />
'''function isArg( $argName )'''<br />
<br />
Return "true" or "false" whether "argName" has been specified as an argument of the AJAX request or not.<br />
<br />
</pre></div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Players_actions:_yourgamename.action.php&diff=492Players actions: yourgamename.action.php2013-01-11T14:56:04Z<p>Sourisdudesert: </p>
<hr />
<div><br />
== Purpose of this file ==<br />
<br />
With this file, you define all the players entry points (ie: possible game actions) of your game.<br />
<br />
This file is a sort of "bridge" between the AJAX calls you are doing from your Javascript client side, and your main PHP code in "yourgame.game.php".<br />
<br />
The role of the methods defined in this file is to filter the arguments, eventually to format them a little bit, and then to call a corresponding PHP method from your main game logic ("yourgame.game.php" file).<br />
<br />
Methods in this file must be short: no game logic must be introduced here.<br />
<br />
== Example of typical action method ==<br />
<br />
(from Reversi example)<br />
<br />
<pre><br />
public function playDisc()<br />
{<br />
self::setAjaxMode(); <br />
$x = self::getArg( "x", AT_posint, true );<br />
$y = self::getArg( "y", AT_posint, true );<br />
$result = $this->game->playDisc( $x, $y );<br />
self::ajaxResponse( );<br />
}<br />
</pre><br />
<br />
== Methods to use in action methods ==<br />
<br />
; function setAjaxMode<br />
: Must be use at the beginning of each action method.<br />
<br />
; function ajaxResponse<br />
: Must be use at the end of each action method.<br />
<br />
; function getArg( $argName, $argType, $mandatory=false, $default=NULL, $argTypeDetails=array(), $bCanFail=false )<br />
: This method must be used to retrieve the arguments sent with your AJAX query.<br />
: You must NOT use "_GET", "_POST" or equivalent PHP variables to do this, as it is unsafe.<br />
: This method use the following arguments:<br />
: * argName: the name of the argument to retrieve.<br />
: * argType: the type of the argument. You should use one of the following:<br />
: 'AT_int' for an integer<br />
: 'AT_posint' for a positive integer <br />
: 'AT_float' for a float<br />
: 'AT_bool' for 1/0/true/false<br />
: 'AT_enum' for an enumeration (argTypeDetails list the possible values as an array)<br />
: 'AT_alphanum' for a string with 0-9a-zA-Z_ and space<br />
<br />
<br />
<br />
: bCanFail means than a validation failure is possible (user input)<br />
: The main argType values are as follows.<br />
<pre><br />
<br />
<br />
; function isArg( $argName )<br />
: Return "true" or "false" whether "argName" has been specified as an argument of the AJAX request or not.<br />
<br />
</pre></div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=491Main game logic: yourgamename.game.php2013-01-11T14:41:59Z<p>Sourisdudesert: /* Accessing database */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see Editing [[Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: The action is valid if it is listed as a "possibleactions" in the current game state (see game state description).<br />
: This method should be called in the first place in ALL your PHP methods that handle players action, in order to make sure a player can't do an action when the rules disallow it at this moment of the game.<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active in the natural player order.<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
; function activePrevPlayer()<br />
: Make the previous player active (in the natural player order).<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Game_database_model:_dbmodel.sql&diff=490Game database model: dbmodel.sql2013-01-11T14:41:22Z<p>Sourisdudesert: Created page with "In this file you specify the database schema of your game. This file contains SQL queries that will be executed during the creation of your game table. Note: you can't chang..."</p>
<hr />
<div>In this file you specify the database schema of your game.<br />
<br />
This file contains SQL queries that will be executed during the creation of your game table.<br />
<br />
Note: you can't change the database schema during the game.<br />
<br />
== Create your schema ==<br />
<br />
To build this file, we recommend you to build the tables you need with the PhpMyAdmin tool (see BGA user guide), and then to export them and to copy/paste the content inside this file.<br />
<br />
== Default tables ==<br />
<br />
Important: by default, BGA creates 4 tables for your game: global, stats, gamelog, and player.<br />
<br />
You must not modify the schema of global, stats and gamelog tables (and you must not access them directly with SQL queries in your PHP code).<br />
<br />
You may add columns to "player" table. This is very practical to add simple values associated with players.<br />
<br />
Example:<br />
<pre><br />
ALTER TABLE `player` ADD `player_reserve_size` SMALLINT UNSIGNED NOT NULL DEFAULT '7';<br />
</pre><br />
<br />
For your information, the useful columns of default "player" table are:<br />
* player_no: the index of player in natural playing order.<br />
* player_id<br />
* player_name: (note: you should better access this date with getActivePlayerName() or loadPlayersBasicInfos() methods)<br />
* player_score: the current score of the player (displayed in the player panel). You must update this field to update player's scores.<br />
* player_score_aux: the secondary score, used as a tie breaker. You must update this field according to tie breaking rules of the game.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=488Main game logic: yourgamename.game.php2013-01-11T14:22:33Z<p>Sourisdudesert: /* Game states and active players */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: The action is valid if it is listed as a "possibleactions" in the current game state (see game state description).<br />
: This method should be called in the first place in ALL your PHP methods that handle players action, in order to make sure a player can't do an action when the rules disallow it at this moment of the game.<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active in the natural player order.<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
; function activePrevPlayer()<br />
: Make the previous player active (in the natural player order).<br />
: Note: you CANT use this method in a "activeplayer" or "multipleactiveplayer" state. You must use a "game" type game state for this.<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=487Main game logic: yourgamename.game.php2013-01-11T14:18:47Z<p>Sourisdudesert: /* Accessing player informations */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=486Your game state machine: states.inc.php2013-01-11T14:16:16Z<p>Sourisdudesert: /* args */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
Note: you may use any ID, even ID greater than 100. But you cannot use 1 and 99.<br />
<br />
Note²: You can't of course use the same ID twice.<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== type ===<br />
<br />
(mandatory)<br />
<br />
You can use 3 types of game states:<br />
* activeplayer (1 player is active and must play)<br />
* multipleactiveplayer (1..N players can be active and must play)<br />
* game (no player is active. This is a transitional state to do something automatic specified by game rules)<br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.<br />
<br />
=== action ===<br />
<br />
(mandatory for "game" game state type)<br />
<br />
"action" specify a PHP method to call when entering into this game state.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
28 => array(<br />
"name" => "startPlayerTurn",<br />
"description" => '',<br />
"type" => "game",<br />
"action" => "stStartPlayerTurn",<br />
<br />
In mygame.game.php:<br />
function stStartPlayerTurn()<br />
{ <br />
// ... do something at the beginning of this game state<br />
</pre><br />
<br />
Usually, for "game" game state type, the action method is used to do some automatic stuff specified by the rules (ex: check victory conditions, deal cards for a new round, go to the next player...) and then jump to another game state.<br />
<br />
Note: a BGA convention specify that PHP method called with "action" are prefixed by "st".<br />
<br />
=== transitions ===<br />
<br />
(mandatory)<br />
<br />
With "transition" you specify in which game state you can jump from a given game state.<br />
<br />
Example:<br />
<pre><br />
25 => array(<br />
"name" => "myGameState",<br />
"transitions" => array( "nextPlayer" => 27, "endRound" => 39 ),<br />
....<br />
}<br />
</pre><br />
<br />
In the example above, if "myGameState" is the current active game state, I can jump to game state with ID 27, or game state with ID 39.<br />
<br />
Example to jump to ID 27:<br />
<pre><br />
In mygame.game.php:<br />
$this->gamestate->nextState( "nextPlayer" );<br />
</pre><br />
<br />
Important: "nextPlayer" is the name of the transition, and NOT the name of the target game state. Several transitions can lead to the same game state.<br />
<br />
Note: if you have only 1 transition, you may give it an empty name.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
"transitions" => array( "" => 27 ),<br />
<br />
In mygame.game.php:<br />
$this->gamestate->nextState( ); // We don't need to specify a transition as there is only one here<br />
</pre><br />
<br />
<br />
=== possibleactions ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states)<br />
<br />
"possibleactions" defines the actions possible by the players at this game state.<br />
<br />
By defining "possibleactions", you make sure players can't do actions that they are not allowed to do at this game states.<br />
<br />
Example:<br />
<br />
<pre><br />
In states.game.php:<br />
"possibleactions" => array( "playCard", "pass" ),<br />
<br />
In mygame.game.php:<br />
function playCard( ...)<br />
{<br />
self::checkAction( "playCard" ); // Will failed if "playCard" is not specified in "possibleactions" in current game state.<br />
<br />
....<br />
<br />
In mygame.js:<br />
playCard: function( ... )<br />
{<br />
if( this.checkAction( "playCard" ) ) // Will failed if "playCard" is not specified in "possibleactions" in current game state.<br />
{ return ; }<br />
<br />
....<br />
<br />
</pre><br />
<br />
=== args ===<br />
<br />
(optional)<br />
<br />
From time to time, it happens that you need some information on the client side (ie : for your game interface) only for a specific game state.<br />
<br />
Example 1 : for Reversi, the list of possible moves during playerTurn state.<br />
Example 2 : in Caylus, the number of remaining king's favor to choose in the state where the player is choosing a favor.<br />
Example 3 : in Can't stop, the list of possible die combination to be displayed to the active player in order he can choose among them.<br />
<br />
In such a situation, you can specify a method name as the « args » argument for your game state. This method must get some piece of information about the game (ex : for Reversi, the possible moves) and return them.<br />
<br />
Thus, this data can be transmitted to the clients and used by the clients to display it.<br />
<br />
Let's see a complete example using args with « Reversi » game :<br />
<br />
In states.inc.php, we specify some « args » argument for gamestate « playerTurn » :<br />
<pre><br />
10 => array(<br />
"name" => "placeWorkers",<br />
"description" => clienttranslate('${actplayer} must place some workers'),<br />
"descriptionmyturn" => clienttranslate('${you} must place some workers'),<br />
"type" => "activeplayer",<br />
"args" => "argPlaceWorkers", <================================== HERE<br />
"possibleactions" => array( "placeWorkers" ),<br />
"transitions" => array( "nextPlayer" => 11, "nextPhase" => 12, "zombiePass" => 11 )<br />
),<br />
</pre><br />
<br />
It corresponds to a « argPlaceWorkers » method in our PHP code (reversi.game.php):<br />
<pre><br />
function argPlayerTurn()<br />
{<br />
return array(<br />
'possibleMoves' => self::getPossibleMoves()<br />
);<br />
}<br />
</pre><br />
<br />
Then, when we enter into « playerTurn » game state on the client side, we can highlight the possible moves on the board using information returned by argPlayerTurn :<br />
<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
{<br />
case 'playerTurn':<br />
this.updatePossibleMoves( args.args.possibleMoves );<br />
break;<br />
}<br />
},<br />
</pre><br />
<br />
Note: you can also used values returned by your "args" method to have some custom values in your "description"/"descriptionmyturn" (see above).<br />
<br />
Note: as a BGA convention, PHP methods called with "args" are prefixed by "arg" (ex: argPlayerTurn).<br />
<br />
=== updateGameProgression ===<br />
<br />
(optional)<br />
<br />
IF you specify "updateGameProgression => true" in a game state, your "getGameProgression" PHP method will be called at the beginning of this game state - and thus the game progression of the game will be updated.<br />
<br />
At least one of your game state (any of them) must specify updateGameProgression=>true.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=485Your game state machine: states.inc.php2013-01-11T14:13:58Z<p>Sourisdudesert: /* possibleactions */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
Note: you may use any ID, even ID greater than 100. But you cannot use 1 and 99.<br />
<br />
Note²: You can't of course use the same ID twice.<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== type ===<br />
<br />
(mandatory)<br />
<br />
You can use 3 types of game states:<br />
* activeplayer (1 player is active and must play)<br />
* multipleactiveplayer (1..N players can be active and must play)<br />
* game (no player is active. This is a transitional state to do something automatic specified by game rules)<br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.<br />
<br />
=== action ===<br />
<br />
(mandatory for "game" game state type)<br />
<br />
"action" specify a PHP method to call when entering into this game state.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
28 => array(<br />
"name" => "startPlayerTurn",<br />
"description" => '',<br />
"type" => "game",<br />
"action" => "stStartPlayerTurn",<br />
<br />
In mygame.game.php:<br />
function stStartPlayerTurn()<br />
{ <br />
// ... do something at the beginning of this game state<br />
</pre><br />
<br />
Usually, for "game" game state type, the action method is used to do some automatic stuff specified by the rules (ex: check victory conditions, deal cards for a new round, go to the next player...) and then jump to another game state.<br />
<br />
Note: a BGA convention specify that PHP method called with "action" are prefixed by "st".<br />
<br />
=== transitions ===<br />
<br />
(mandatory)<br />
<br />
With "transition" you specify in which game state you can jump from a given game state.<br />
<br />
Example:<br />
<pre><br />
25 => array(<br />
"name" => "myGameState",<br />
"transitions" => array( "nextPlayer" => 27, "endRound" => 39 ),<br />
....<br />
}<br />
</pre><br />
<br />
In the example above, if "myGameState" is the current active game state, I can jump to game state with ID 27, or game state with ID 39.<br />
<br />
Example to jump to ID 27:<br />
<pre><br />
In mygame.game.php:<br />
$this->gamestate->nextState( "nextPlayer" );<br />
</pre><br />
<br />
Important: "nextPlayer" is the name of the transition, and NOT the name of the target game state. Several transitions can lead to the same game state.<br />
<br />
Note: if you have only 1 transition, you may give it an empty name.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
"transitions" => array( "" => 27 ),<br />
<br />
In mygame.game.php:<br />
$this->gamestate->nextState( ); // We don't need to specify a transition as there is only one here<br />
</pre><br />
<br />
<br />
=== possibleactions ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states)<br />
<br />
"possibleactions" defines the actions possible by the players at this game state.<br />
<br />
By defining "possibleactions", you make sure players can't do actions that they are not allowed to do at this game states.<br />
<br />
Example:<br />
<br />
<pre><br />
In states.game.php:<br />
"possibleactions" => array( "playCard", "pass" ),<br />
<br />
In mygame.game.php:<br />
function playCard( ...)<br />
{<br />
self::checkAction( "playCard" ); // Will failed if "playCard" is not specified in "possibleactions" in current game state.<br />
<br />
....<br />
<br />
In mygame.js:<br />
playCard: function( ... )<br />
{<br />
if( this.checkAction( "playCard" ) ) // Will failed if "playCard" is not specified in "possibleactions" in current game state.<br />
{ return ; }<br />
<br />
....<br />
<br />
</pre><br />
<br />
=== args ===<br />
<br />
(optional)<br />
<br />
From time to time, it happens that you need some information on the client side (ie : for your game interface) only for a specific game state.<br />
<br />
Example 1 : for Reversi, the list of possible moves during playerTurn state.<br />
Example 2 : in Caylus, the number of remaining king's favor to choose in the state where the player is choosing a favor.<br />
Example 3 : in Can't stop, the list of possible die combination to be displayed to the active player in order he can choose among them.<br />
<br />
In such a situation, you can specify a method name as the « args » argument for your game state. This method must get some piece of information about the game (ex : for Reversi, the possible moves) and return them.<br />
<br />
Thus, this data can be transmitted to the clients and used by the clients to display it.<br />
<br />
Let's see a complete example using args with « Reversi » game :<br />
<br />
In states.inc.php, we specify some « args » argument for gamestate « playerTurn » :<br />
<pre><br />
10 => array(<br />
"name" => "placeWorkers",<br />
"description" => clienttranslate('${actplayer} must place some workers'),<br />
"descriptionmyturn" => clienttranslate('${you} must place some workers'),<br />
"type" => "activeplayer",<br />
'''"args" => "argPlaceWorkers",'''<br />
"possibleactions" => array( "placeWorkers" ),<br />
"transitions" => array( "nextPlayer" => 11, "nextPhase" => 12, "zombiePass" => 11 )<br />
),<br />
</pre><br />
=== updateGameProgression ===<br />
<br />
(optional)<br />
<br />
IF you specify "updateGameProgression => true" in a game state, your "getGameProgression" PHP method will be called at the beginning of this game state - and thus the game progression of the game will be updated.<br />
<br />
At least one of your game state (any of them) must specify updateGameProgression=>true.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=484Your game state machine: states.inc.php2013-01-11T14:08:14Z<p>Sourisdudesert: /* possibleactions */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
Note: you may use any ID, even ID greater than 100. But you cannot use 1 and 99.<br />
<br />
Note²: You can't of course use the same ID twice.<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== type ===<br />
<br />
(mandatory)<br />
<br />
You can use 3 types of game states:<br />
* activeplayer (1 player is active and must play)<br />
* multipleactiveplayer (1..N players can be active and must play)<br />
* game (no player is active. This is a transitional state to do something automatic specified by game rules)<br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.<br />
<br />
=== action ===<br />
<br />
(mandatory for "game" game state type)<br />
<br />
"action" specify a PHP method to call when entering into this game state.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
28 => array(<br />
"name" => "startPlayerTurn",<br />
"description" => '',<br />
"type" => "game",<br />
"action" => "stStartPlayerTurn",<br />
<br />
In mygame.game.php:<br />
function stStartPlayerTurn()<br />
{ <br />
// ... do something at the beginning of this game state<br />
</pre><br />
<br />
Usually, for "game" game state type, the action method is used to do some automatic stuff specified by the rules (ex: check victory conditions, deal cards for a new round, go to the next player...) and then jump to another game state.<br />
<br />
Note: a BGA convention specify that PHP method called with "action" are prefixed by "st".<br />
<br />
=== transitions ===<br />
<br />
(mandatory)<br />
<br />
With "transition" you specify in which game state you can jump from a given game state.<br />
<br />
Example:<br />
<pre><br />
25 => array(<br />
"name" => "myGameState",<br />
"transitions" => array( "nextPlayer" => 27, "endRound" => 39 ),<br />
....<br />
}<br />
</pre><br />
<br />
In the example above, if "myGameState" is the current active game state, I can jump to game state with ID 27, or game state with ID 39.<br />
<br />
Example to jump to ID 27:<br />
<pre><br />
In mygame.game.php:<br />
$this->gamestate->nextState( "nextPlayer" );<br />
</pre><br />
<br />
Important: "nextPlayer" is the name of the transition, and NOT the name of the target game state. Several transitions can lead to the same game state.<br />
<br />
Note: if you have only 1 transition, you may give it an empty name.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
"transitions" => array( "" => 27 ),<br />
<br />
In mygame.game.php:<br />
$this->gamestate->nextState( ); // We don't need to specify a transition as there is only one here<br />
</pre><br />
<br />
<br />
=== possibleactions ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states)<br />
<br />
"possibleactions" defines the actions possible by the players at this game state.<br />
<br />
By defining "possibleactions", you make sure players can't do actions that they are not allowed to do at this game states.<br />
<br />
Example:<br />
<br />
<pre><br />
In states.game.php:<br />
"possibleactions" => array( "playCard", "pass" ),<br />
<br />
In mygame.game.php:<br />
function playCard( ...)<br />
{<br />
self::checkAction( "playCard" ); // Will failed if "playCard" is not specified in "possibleactions" in current game state.<br />
<br />
....<br />
<br />
In mygame.js:<br />
playCard: function( ... )<br />
{<br />
if( this.checkAction( "playCard" ) ) // Will failed if "playCard" is not specified in "possibleactions" in current game state.<br />
{ return ; }<br />
<br />
....<br />
<br />
</pre></div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=483Your game state machine: states.inc.php2013-01-11T14:07:59Z<p>Sourisdudesert: /* transitions */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
Note: you may use any ID, even ID greater than 100. But you cannot use 1 and 99.<br />
<br />
Note²: You can't of course use the same ID twice.<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== type ===<br />
<br />
(mandatory)<br />
<br />
You can use 3 types of game states:<br />
* activeplayer (1 player is active and must play)<br />
* multipleactiveplayer (1..N players can be active and must play)<br />
* game (no player is active. This is a transitional state to do something automatic specified by game rules)<br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.<br />
<br />
=== action ===<br />
<br />
(mandatory for "game" game state type)<br />
<br />
"action" specify a PHP method to call when entering into this game state.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
28 => array(<br />
"name" => "startPlayerTurn",<br />
"description" => '',<br />
"type" => "game",<br />
"action" => "stStartPlayerTurn",<br />
<br />
In mygame.game.php:<br />
function stStartPlayerTurn()<br />
{ <br />
// ... do something at the beginning of this game state<br />
</pre><br />
<br />
Usually, for "game" game state type, the action method is used to do some automatic stuff specified by the rules (ex: check victory conditions, deal cards for a new round, go to the next player...) and then jump to another game state.<br />
<br />
Note: a BGA convention specify that PHP method called with "action" are prefixed by "st".<br />
<br />
=== transitions ===<br />
<br />
(mandatory)<br />
<br />
With "transition" you specify in which game state you can jump from a given game state.<br />
<br />
Example:<br />
<pre><br />
25 => array(<br />
"name" => "myGameState",<br />
"transitions" => array( "nextPlayer" => 27, "endRound" => 39 ),<br />
....<br />
}<br />
</pre><br />
<br />
In the example above, if "myGameState" is the current active game state, I can jump to game state with ID 27, or game state with ID 39.<br />
<br />
Example to jump to ID 27:<br />
<pre><br />
In mygame.game.php:<br />
$this->gamestate->nextState( "nextPlayer" );<br />
</pre><br />
<br />
Important: "nextPlayer" is the name of the transition, and NOT the name of the target game state. Several transitions can lead to the same game state.<br />
<br />
Note: if you have only 1 transition, you may give it an empty name.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
"transitions" => array( "" => 27 ),<br />
<br />
In mygame.game.php:<br />
$this->gamestate->nextState( ); // We don't need to specify a transition as there is only one here<br />
</pre><br />
<br />
<br />
=== possibleactions ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states)<br />
<br />
"possibleactions" defines the actions possible by the players at this game state.<br />
<br />
By defining "possibleactions", you make sure players can't do actions that they are not allowed to do at this game states.<br />
<br />
Example:<br />
<br />
<pre><br />
In states.game.php:<br />
"possibleactions" => array( "playCard", "pass" ),<br />
<br />
In mygame.game.php:<br />
function playCard( ...)<br />
{<br />
self::checkAction( "playCard" ); // Will failed if "playCard" is not specified in "possibleactions" in current game state.<br />
<br />
....<br />
<br />
In mygame.js:<br />
playCard: function( ... )<br />
{<br />
if( this.checkAction( "playCard" ) )<br />
{ return ; }<br />
<br />
....<br />
<br />
</pre></div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=482Your game state machine: states.inc.php2013-01-11T14:02:57Z<p>Sourisdudesert: /* action */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
Note: you may use any ID, even ID greater than 100. But you cannot use 1 and 99.<br />
<br />
Note²: You can't of course use the same ID twice.<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== type ===<br />
<br />
(mandatory)<br />
<br />
You can use 3 types of game states:<br />
* activeplayer (1 player is active and must play)<br />
* multipleactiveplayer (1..N players can be active and must play)<br />
* game (no player is active. This is a transitional state to do something automatic specified by game rules)<br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.<br />
<br />
=== action ===<br />
<br />
(mandatory for "game" game state type)<br />
<br />
"action" specify a PHP method to call when entering into this game state.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
28 => array(<br />
"name" => "startPlayerTurn",<br />
"description" => '',<br />
"type" => "game",<br />
"action" => "stStartPlayerTurn",<br />
<br />
In mygame.game.php:<br />
function stStartPlayerTurn()<br />
{ <br />
// ... do something at the beginning of this game state<br />
</pre><br />
<br />
Usually, for "game" game state type, the action method is used to do some automatic stuff specified by the rules (ex: check victory conditions, deal cards for a new round, go to the next player...) and then jump to another game state.<br />
<br />
Note: a BGA convention specify that PHP method called with "action" are prefixed by "st".<br />
<br />
=== transitions ===<br />
<br />
With "transition" you specify in which game state you can jump from a given game state.<br />
<br />
Example:<br />
<pre><br />
25 => array(<br />
"name" => "myGameState",<br />
"transitions" => array( "nextPlayer" => 27, "endRound" => 39 ),<br />
....<br />
}<br />
</pre><br />
<br />
In the example above, if "myGameState" is the current active game state, I can jump to game state with ID 27, or game state with ID 39.<br />
<br />
Example to jump to ID 27:<br />
<pre><br />
In mygame.game.php:<br />
$this->gamestate->nextState( "nextPlayer" );<br />
</pre><br />
<br />
Important: "nextPlayer" is the name of the transition, and NOT the name of the target game state. Several transitions can lead to the same game state.<br />
<br />
Note: if you have only 1 transition, you may give it an empty name.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
"transitions" => array( "" => 27 ),<br />
<br />
In mygame.game.php:<br />
$this->gamestate->nextState( ); // We don't need to specify a transition as there is only one here<br />
</pre></div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=481Your game state machine: states.inc.php2013-01-11T13:52:19Z<p>Sourisdudesert: /* id */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
Note: you may use any ID, even ID greater than 100. But you cannot use 1 and 99.<br />
<br />
Note²: You can't of course use the same ID twice.<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== type ===<br />
<br />
(mandatory)<br />
<br />
You can use 3 types of game states:<br />
* activeplayer (1 player is active and must play)<br />
* multipleactiveplayer (1..N players can be active and must play)<br />
* game (no player is active. This is a transitional state to do something automatic specified by game rules)<br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.<br />
<br />
=== action ===<br />
<br />
(mandatory for "game" game state type)<br />
<br />
"action" specify a PHP method to call when entering into this game state.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
28 => array(<br />
"name" => "startPlayerTurn",<br />
"description" => '',<br />
"type" => "game",<br />
"action" => "stStartPlayerTurn",<br />
<br />
In mygame.game.php:<br />
function stStartPlayerTurn()<br />
{ <br />
// ... do something at the beginning of this game state<br />
</pre><br />
<br />
Usually, for "game" game state type, the action method is used to do some automatic stuff specified by the rules (ex: check victory conditions, deal cards for a new round, go to the next player...) and then jump to another game state.<br />
<br />
Note: a BGA convention specify that PHP method called with "action" are prefixed by "st".</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=480Your game state machine: states.inc.php2013-01-11T13:52:11Z<p>Sourisdudesert: /* id */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
Note: you may use any ID, even ID greater than 100. But you cannot use 1 and 99.<br />
Note²: You can't of course use the same ID twice.<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== type ===<br />
<br />
(mandatory)<br />
<br />
You can use 3 types of game states:<br />
* activeplayer (1 player is active and must play)<br />
* multipleactiveplayer (1..N players can be active and must play)<br />
* game (no player is active. This is a transitional state to do something automatic specified by game rules)<br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.<br />
<br />
=== action ===<br />
<br />
(mandatory for "game" game state type)<br />
<br />
"action" specify a PHP method to call when entering into this game state.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
28 => array(<br />
"name" => "startPlayerTurn",<br />
"description" => '',<br />
"type" => "game",<br />
"action" => "stStartPlayerTurn",<br />
<br />
In mygame.game.php:<br />
function stStartPlayerTurn()<br />
{ <br />
// ... do something at the beginning of this game state<br />
</pre><br />
<br />
Usually, for "game" game state type, the action method is used to do some automatic stuff specified by the rules (ex: check victory conditions, deal cards for a new round, go to the next player...) and then jump to another game state.<br />
<br />
Note: a BGA convention specify that PHP method called with "action" are prefixed by "st".</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=479Your game state machine: states.inc.php2013-01-11T13:51:07Z<p>Sourisdudesert: /* descriptionmyturn */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== type ===<br />
<br />
(mandatory)<br />
<br />
You can use 3 types of game states:<br />
* activeplayer (1 player is active and must play)<br />
* multipleactiveplayer (1..N players can be active and must play)<br />
* game (no player is active. This is a transitional state to do something automatic specified by game rules)<br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.<br />
<br />
=== action ===<br />
<br />
(mandatory for "game" game state type)<br />
<br />
"action" specify a PHP method to call when entering into this game state.<br />
<br />
Example:<br />
<pre><br />
In states.inc.php:<br />
28 => array(<br />
"name" => "startPlayerTurn",<br />
"description" => '',<br />
"type" => "game",<br />
"action" => "stStartPlayerTurn",<br />
<br />
In mygame.game.php:<br />
function stStartPlayerTurn()<br />
{ <br />
// ... do something at the beginning of this game state<br />
</pre><br />
<br />
Usually, for "game" game state type, the action method is used to do some automatic stuff specified by the rules (ex: check victory conditions, deal cards for a new round, go to the next player...) and then jump to another game state.<br />
<br />
Note: a BGA convention specify that PHP method called with "action" are prefixed by "st".</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=478Your game state machine: states.inc.php2013-01-11T13:45:32Z<p>Sourisdudesert: /* Syntax */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== type ===<br />
<br />
(mandatory)<br />
<br />
You can use 3 types of game states:<br />
* activeplayer (1 player is active and must play)<br />
* multipleactiveplayer (1..N players can be active and must play)<br />
* game (no player is active. This is a transitional state to do something automatic specified by game rules)<br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=477Your game state machine: states.inc.php2013-01-11T13:43:48Z<p>Sourisdudesert: /* descriptionmyturn */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
=== descriptionmyturn ===<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=476Your game state machine: states.inc.php2013-01-11T13:43:42Z<p>Sourisdudesert: /* description */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
=== description ===<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
== descriptionmyturn ==<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=475Your game state machine: states.inc.php2013-01-11T13:43:11Z<p>Sourisdudesert: /* descriptionmyturn */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
== description ==<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
== descriptionmyturn ==<br />
<br />
(mandatory for "activeplayer" and "multipleactiveplayer" game states type)<br />
<br />
"descriptionmyturn" has exactly the same role and properties than "description", except that this value is displayed to the current active player - or to all active players in case of a multipleactiveplayer game state.<br />
<br />
In general, we have this situation:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} can take some actions'),<br />
"descriptionmyturn" => clienttranslate('${you} can take some actions'),<br />
</pre><br />
<br />
Note: you can use ${you} in description my turn in order the description can display "You" instead of the name of the player.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=474Your game state machine: states.inc.php2013-01-11T13:39:01Z<p>Sourisdudesert: /* Syntax */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== id ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
=== name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre><br />
<br />
== description ==<br />
<br />
(mandatory)<br />
<br />
The description is the string that is displayed in the main action bar (top of the screen) when the state is active.<br />
<br />
When a string is specified as a description, you must use "clienttranslate" in order the string can be translate on the client side:<br />
<br />
<pre><br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
</pre><br />
<br />
In the description string, you can use ${actplayer} to refer to the active player.<br />
<br />
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).<br />
<br />
Example of custom field:<br />
<pre><br />
<br />
In states.inc.php:<br />
"description" => clienttranslate('${actplayer} must choose ${nbr} identical energies'),<br />
"arg" => "argMyArgumentMethod"<br />
<br />
In mygame.game.php:<br />
function argMyArgumentMethod()<br />
{<br />
return array(<br />
'nbr' => 2 // In this case ${nbr} in the description will be replaced by "2"<br />
); <br />
}<br />
</pre><br />
<br />
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).<br />
<br />
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.<br />
<br />
== descriptionmyturn ==</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=473Your game state machine: states.inc.php2013-01-11T13:24:58Z<p>Sourisdudesert: /* Game state name */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== Game state ID ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
=== Game state name ===<br />
<br />
(mandatory)<br />
<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
Several game states can share the same name, however this is not recommended.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre></div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=472Your game state machine: states.inc.php2013-01-11T13:24:31Z<p>Sourisdudesert: /* Syntax */</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== Game state ID ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).<br />
<br />
=== Game state name ===<br />
<br />
(mandatory)<br />
The name of a game state is used to identify it in your game logic.<br />
<br />
PHP example:<br />
<pre><br />
<br />
// Get current game state<br />
$state = $this->gamestate->state();<br />
if( $state['name'] == 'myGameState' )<br />
{<br />
...<br />
}<br />
<br />
</pre><br />
<br />
JS example:<br />
<pre><br />
onEnteringState: function( stateName, args )<br />
{<br />
console.log( 'Entering state: '+stateName );<br />
<br />
switch( stateName )<br />
case 'myGameState':<br />
<br />
// Do some stuff at the beginning at this game state<br />
....<br />
<br />
break;<br />
</pre></div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Your_game_state_machine:_states.inc.php&diff=471Your game state machine: states.inc.php2013-01-11T13:19:50Z<p>Sourisdudesert: 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..."</p>
<hr />
<div><br />
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).<br />
<br />
Important: to understand the game state machine, the best is to read this presentation first:<br />
<br />
[http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
<br />
== Overall structure ==<br />
<br />
The machine states is described by a PHP associative array.<br />
<br />
Example:<br />
<br />
<pre><br />
$machinestates = array(<br />
<br />
// The initial state. Please do not modify.<br />
1 => array(<br />
"name" => "gameSetup",<br />
"description" => clienttranslate("Game setup"),<br />
"type" => "manager",<br />
"action" => "stGameSetup",<br />
"transitions" => array( "" => 2 )<br />
),<br />
<br />
// Note: ID=2 => your first state<br />
<br />
2 => array(<br />
"name" => "playerTurn",<br />
"description" => clienttranslate('${actplayer} must play a card or pass'),<br />
"descriptionmyturn" => clienttranslate('${you} must play a card or pass'),<br />
"type" => "activeplayer",<br />
"possibleactions" => array( "playCard", "pass" ),<br />
"transitions" => array( "playCard" => 2, "pass" => 2 )<br />
),<br />
</pre><br />
<br />
== Syntax ==<br />
<br />
=== Game state ID ===<br />
<br />
The keys determine game states IDs (in the example above: 1 and 2).<br />
<br />
IDs must be positive integers.<br />
<br />
ID=1 is reserved for the first game state and should not be used (and you must not modify it).<br />
<br />
ID=99 is reserved for the last game state of the game (end of the game) (and you must not modify it).</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Studio&diff=470Studio2013-01-11T12:06:01Z<p>Sourisdudesert: /* BGA Studio documentation */</p>
<hr />
<div>[[File:Bga_studio_small.jpg]]<br />
<br />
Note: Please DO NOT translate Studio Documentation, so that there can be one place where you can find the last information available.<br />
<br />
== What is Board Game Arena Studio? ==<br />
<br />
'''Board Game Arena Studio''' is a platform to build online board game adaptation using the Board Game Arena platform.<br />
<br />
It is open to any gamer with development skills :)<br />
<br />
See announcement here:<br />
http://forum.boardgamearena.com/viewtopic.php?f=10&t=1973<br />
<br />
== Discover BGA Studio in 5 presentations ==<br />
<br />
Why, how, what... to start discovering BGA Studio, we prepare you 5 "powerpoint" presentations:<br />
<br />
* [http://www.slideshare.net/boardgamearena/5-reasons-why-you-should-use-bga-studio-for-your-online-board-game 5 reasons why you should use BGA Studio for your online board game]<br />
* [http://www.slideshare.net/boardgamearena/the-8-steps-to-create-a-board-game-on-board-game-arena The 8 steps to create a board game on Board Game Arena]<br />
* [http://www.slideshare.net/boardgamearena/the-bga-framework-at-a-glance The BGA Framework at a glance]<br />
* [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine]<br />
* [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines]<br />
<br />
== How to join BGA developer team? ==<br />
<br />
Please see: [[How to join BGA developer team?]]<br />
<br />
== Great, I'm in! ... How should I start? ==<br />
<br />
If you didn't already, check the presentations at the top of this page to get the basics.<br />
<br />
After that, we would advise you to take a peek at one or both of these two game creation tutorials:<br />
* [[Tutorial reversi]]<br />
* [[Tutorial gomoku]]<br />
<br />
Then start editing files and see what happens! ;)<br />
<br />
If you have any questions, please ask them on the [http://forum.boardgamearena.com/viewforum.php?f=12 development forum].<br />
<br />
== BGA Studio documentation ==<br />
<br />
[[Studio FAQ]]<br />
<br />
=== BGA Studio Framework reference ===<br />
<br />
This part of the documentation focus on the development framework itself: functions and methods available to build your game.<br />
<br />
[[Studio file reference|File structure of a BGA game]]<br />
<br />
==== Game logic ====<br />
<br />
* [[Main game logic: yourgamename.game.php]]<br />
* [[Your game state machine: states.inc.php]]<br />
* [[Game database model: dbmodel.sql]]<br />
* [[Players actions: yourgamename.action.php]]<br />
* [[Game material description: material.inc.php]]<br />
* [[Game statistics: stats.inc.php]]<br />
<br />
==== Game interface ====<br />
<br />
* [[Game interface logic: yourgamename.js]]<br />
* [[Game art: img directory]]<br />
* [[Game interface stylesheet: yourgamename.css]]<br />
* [[Game layout: view and template: yourgamename.view.php and yourgamename_yourgamename.tpl]]<br />
<br />
==== Other components ====<br />
<br />
* [[Game options and preferences: gameoptions.inc.php]]<br />
<br />
<br />
=== BGA Studio game components reference ===<br />
<br />
Game components are useful tools you can use in your game adaptations.<br />
<br />
* [[Deck]]: a PHP component to manage cards (deck, hands, picking cards, moving cards, shuffle deck, ...).<br />
* [[Counter]]: a JS component to manage a counter that can increase/decrease (ex: player's score).<br />
* [[Draggable]]: a JS component to manage drag'n'drop actions.<br />
* [[ExpandableSection]]: a JS component to manage a rectangular block of HTML than can be displayed/hide.<br />
* [[Scrollmap]]: a JS component to manage a scrollable game area (useful when the game area can be infinite. Examples: Saboteur or Takenoko games).<br />
* [[Stock]]: a JS component to manage and display a set of game elements displayed at a position.<br />
* [[Wrapper]]: a JS component to wrap a <div> element around his child, even if these elements are absolute positioned.<br />
* [[Zone]]: a JS component to manage a zone of the board where several game elements can come and leave, but should be well displayed together (See for example: token's places at Can't Stop).<br />
<br />
=== BGA Studio user guide ===<br />
<br />
This part of the documentation is a user guide for the BGA Studio online development environment.<br />
<br />
[[Studio back-office]]<br />
<br />
== Other resources ==<br />
<br />
[http://forum.boardgamearena.com/viewforum.php?f=12 Development forum]<br />
<br />
[http://forum.boardgamearena.com/viewforum.php?f=4 Bugs forum]</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=469Main game logic: yourgamename.game.php2013-01-11T11:51:35Z<p>Sourisdudesert: /* Accessing player informations */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: * player_name<br />
: * player_color (ex: ff0000)<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=468Main game logic: yourgamename.game.php2013-01-11T11:48:42Z<p>Sourisdudesert: </p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you.<br />
<br />
Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
: Note: doesn't work in setupNewGame so use count($players) instead<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: TODO<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=466Main game logic: yourgamename.game.php2013-01-05T11:23:52Z<p>Sourisdudesert: /* Accessing player informations */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you. Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; getActivePlayerName()<br />
: Get the "active_player" name<br />
<br />
; loadPlayersBasicInfos()<br />
: Get an associative array with generic data about players (ie: not game specific data).<br />
: The key of the associative array is the player id.<br />
: The content of each value is:<br />
: TODO<br />
<br />
; getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=465Main game logic: yourgamename.game.php2013-01-05T11:19:55Z<p>Sourisdudesert: /* Accessing player informations */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you. Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
<br />
; getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type.<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
: Note: avoid using this method in a "multiplayer" state because it does not mean anything.<br />
<br />
; function getActivePlayerName()<br />
: Get the "active_player" name<br />
<br />
; function getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated (the one who send the request).<br />
: '''Be careful''': It is not always the active player.<br />
: In general, you shouldn't use this method, unless you are in "multiplayer" state.<br />
<br />
; function getCurrentPlayerName()<br />
: Get the "current_player" name<br />
: Be careful using this method (see above).<br />
<br />
; function getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
: Be careful using this method (see above).<br />
<br />
; function isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status. If true, player leave the game.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=464Main game logic: yourgamename.game.php2013-01-05T11:15:56Z<p>Sourisdudesert: </p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you. Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing player informations ==<br />
<br />
; function getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
; function getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
; function getActivePlayerName()<br />
: Get the "active_player" name<br />
; function getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated. It is not always the active player.<br />
; function getCurrentPlayerName()<br />
: Get the "current_player" name<br />
; function getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
; function isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status<br />
<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
== Game states and active players ==<br />
<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
<br />
<br />
== Notify players ==<br />
<br />
== Game statistics ==<br />
<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
<br />
== Translations ==<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
<br />
== Reflexion time ==<br />
<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
<br />
<br />
== Managing errors and exceptions ==<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=463Main game logic: yourgamename.game.php2013-01-05T11:10:28Z<p>Sourisdudesert: /* Accessing database */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you. Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
=== Table class (<gamename>.game.php) ===<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
; function getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
; function getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
; function getActivePlayerName()<br />
: Get the "active_player" name<br />
; function getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated. It is not always the active player.<br />
; function getCurrentPlayerName()<br />
: Get the "current_player" name<br />
; function getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
; function isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
=== Exceptions you can throw ===<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=462Main game logic: yourgamename.game.php2013-01-05T11:10:05Z<p>Sourisdudesert: /* Accessing database */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you. Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0',<br />
1235 => 'myuser1'<br />
)<br />
<br />
</pre><br />
<br />
; getNonEmptyCollectionFromDB( $sql )<br />
: Idem than previous one, but raise an exception if the collection is empty<br />
<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql SELECT query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
<br />
<pre><br />
self::getObjectFromDB( "SELECT player_id id, player_name name, player_color color FROM player WHERE player_id='1234'" );<br />
<br />
Result:<br />
array(<br />
'id' => 1234,<br />
'name' => 'myuser1',<br />
'color' => 'ff0000'<br />
)<br />
<br />
</pre><br />
<br />
<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
=== Table class (<gamename>.game.php) ===<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
; function getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
; function getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
; function getActivePlayerName()<br />
: Get the "active_player" name<br />
; function getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated. It is not always the active player.<br />
; function getCurrentPlayerName()<br />
: Get the "current_player" name<br />
; function getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
; function isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
=== Exceptions you can throw ===<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=461Main game logic: yourgamename.game.php2013-01-05T11:07:26Z<p>Sourisdudesert: /* Accessing database */</p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you. Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; function DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; function getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; function getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
Example 1:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
</pre><br />
Example 2:<br />
<pre><br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0' ),<br />
1235 => 'myuser1' )<br />
)<br />
<br />
</pre><br />
<br />
; protected function getNonEmptyCollectionFromDB( $sql )<br />
: Idem, but raise an exception if the collection is empty<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
=== Table class (<gamename>.game.php) ===<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
; function getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
; function getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
; function getActivePlayerName()<br />
: Get the "active_player" name<br />
; function getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated. It is not always the active player.<br />
; function getCurrentPlayerName()<br />
: Get the "current_player" name<br />
; function getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
; function isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
=== Exceptions you can throw ===<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=460Main game logic: yourgamename.game.php2013-01-05T11:06:45Z<p>Sourisdudesert: </p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you. Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
== Accessing database ==<br />
<br />
The main game logic should be the only point from where you should access to the game database. You access your database using SQL queries with the following methods:<br />
<br />
; function DbQuery( $sql )<br />
: This is the generic method to access the database.<br />
: It can execute any type of SELECT/UPDATE/DELETE/REPLACE query on the database.<br />
: You should use it for UPDATE/DELETE/REPLACE query. For SELECT queries, the specialized methods above are much better.<br />
<br />
; function getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found.<br />
: $sql must be a SELECT query.<br />
: Raise an exception if more than 1 row is returned.<br />
<br />
; function getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for a sql SELECT query.<br />
: The key of the resulting associative array is the first field specified in the SELECT query.<br />
: The value of the resulting associative array if an associative array with all the field specified in the SELECT query and associated values.<br />
: First column must be a primary or alternate key.<br />
: The resulting collection can be empty.<br />
: If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B"<br />
<br />
<pre><br />
<br />
Example 1:<br />
<br />
self::getCollectionFromDB( "SELECT player_id id, player_name name, player_score score FROM player" );<br />
<br />
Result:<br />
array(<br />
1234 => array( 'id'=>1234, 'name'=>'myuser0', 'score'=>1 ),<br />
1235 => array( 'id'=>1235, 'name'=>'myuser1', 'score'=>0 )<br />
)<br />
<br />
Example 2:<br />
<br />
self::getCollectionFromDB( "SELECT player_id id, player_name name FROM player", true );<br />
<br />
Result:<br />
array(<br />
1234 => 'myuser0' ),<br />
1235 => 'myuser1' )<br />
)<br />
<br />
</pre><br />
<br />
; protected function getNonEmptyCollectionFromDB( $sql )<br />
: Idem, but raise an exception if the collection is empty<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
<br />
<br />
Note: see [[Editing Game database model: dbmodel.sql]] to know how to define your database model.<br />
<br />
=== Table class (<gamename>.game.php) ===<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
; function getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
; function getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
; function getActivePlayerName()<br />
: Get the "active_player" name<br />
; function getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated. It is not always the active player.<br />
; function getCurrentPlayerName()<br />
: Get the "current_player" name<br />
; function getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
; function isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
<br />
=== Exceptions you can throw ===<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Main_game_logic:_yourgamename.game.php&diff=459Main game logic: yourgamename.game.php2013-01-05T10:51:52Z<p>Sourisdudesert: </p>
<hr />
<div><br />
This file is the main file for your game logic. Here you initialize the game, persist data, implement the rules and notify changes to the client interface.<br />
<br />
== File Structure ==<br />
<br />
The details on how the file is structured is described directly with comments on the code skeleton provided to you. Basically, here's this structure:<br />
* EmptyGame (constructor): where you define global variables.<br />
* setupNewGame: initial setup of the game.<br />
* getAllDatas: where you retrieve all game data during a complete reload of the game.<br />
* getGameProgression: where you compute the game progression indicator.<br />
* Utility functions: your utility functions.<br />
* Player actions: the entry points for players actions. <br />
* Game state arguments: methods to return additional data on specific game states.<br />
* Game state actions: the logic to run when entering a new game state.<br />
* zombieTurn: what to do it's the turn of a zombie player.<br />
<br />
<br />
=== Table class (<gamename>.game.php) ===<br />
<br />
; function _( $text )<br />
: Transparent function, used to mark strings to be translated on the server side (ex: error message)<br />
; function clienttranslate( $string )<br />
: Transparent function: used to mark string to be translated on client side (ex: notification message)<br />
; function getPlayersNumber()<br />
: Returns the number of players playing at the table<br />
; function checkAction( $actionName, $bThrowException=true )<br />
: Check if action is valid regarding current game state (exception if fails)<br />
: if "bThrowException" is set to "false", the function return false in case of failure instead of throwing and exception<br />
; function getActivePlayerId()<br />
: Get the "active_player", whatever what is the current state type<br />
: Note: it does NOT mean that this player is active right now, because state type could be "game" or "multiplayer"<br />
; function getActivePlayerName()<br />
: Get the "active_player" name<br />
; function getCurrentPlayerId()<br />
: Get the "current_player". The current player is the one from which the action originated. It is not always the active player.<br />
; function getCurrentPlayerName()<br />
: Get the "current_player" name<br />
; function getCurrentPlayerColor()<br />
: Get the "current_player" color<br />
; function isCurrentPlayerZombie()<br />
: Check the "current_player" zombie status<br />
; function activeNextPlayer()<br />
: Make the next player active<br />
; function activePrevPlayer()<br />
: Make the previous player active<br />
; function giveExtraTime( $player_id, $specific_time=null )<br />
: Give standard extra time to this player (standard extra time is a game option)<br />
; function initStat( $table_or_player, $name, $value, $player_id=null )<br />
: Create a statistic entry for the specified statistics with a default value<br />
: In case of a "player" entry, if player_id is not specified, all players are set to the same value<br />
; function setStat( $value, $name, $player_id = null )<br />
: Set statistic value<br />
; function incStat( $delta, $name, $player_id = null )<br />
: Increment (or decrement) specified value<br />
; function DbQuery( $sql )<br />
: Executes sql query on the database<br />
; function getCollectionFromDB( $sql, $bSingleValue=false )<br />
: Returns an associative array of rows for the sql query. First column must be a primary or alternate key. The resulting collection can be empty.<br />
; protected function getNonEmptyCollectionFromDB( $sql )<br />
: Idem, but raise an exception if the collection is empty<br />
; function getUniqueValueFromDB( $sql )<br />
: Returns a unique value from DB or null if no value is found<br />
: Raise an exception if more than 1 row is returned<br />
; function getObjectFromDB( $sql )<br />
: Returns one row for the sql query as an associative array or null if there is no result<br />
: Raise an exception if the query return more than one row<br />
; function getNonEmptyObjectFromDB( $sql )<br />
: Idem, but raise an exception if the query doesn't return exactly one row<br />
<br />
=== Exceptions you can throw ===<br />
<br />
; throw new BgaUserException ( $error_message)<br />
: Base class to notify a user error<br />
; throw new BgaSystemException ( $error_message)<br />
: Base class to notify a system exception. The message will be hidden from the user, but show in the logs. Use this if the message contains technical information.<br />
; throw new BgaSystemVisibleException ( $error_message)<br />
: Same as previous, except that the message is visible by the user. You can use this if the message is understandable by the user.</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Game_art:_img_directory&diff=458Game art: img directory2013-01-05T10:43:51Z<p>Sourisdudesert: /* Requested images */</p>
<hr />
<div>== Requested images ==<br />
<br />
The following images are requested by BGA:<br />
<br />
;game_box.png<br />
* It is displayed on the main site on the game description page and when creating a table (280x280 px).<br />
* It should be an image of a physical copy of the game box as it appears in an online shop.<br />
* It is better to take the version of the game that is coherent with the game art used in the adaptation, and from the original publisher of the game.<br />
* The background of the image must be transparent.<br />
<br />
;game_icon.png<br />
<br />
* It is the icon displayed in the lists of games and tables (50x50 px).<br />
* This one should not be transparent, and shouldn't have a border (a black border will be add by BGA).<br />
* The objective of this icon is to make the game recognizable among the other games. A good idea is to take a part of the game cover that is distinctive (ex: the game title).<br />
<br />
;publisher.png<br />
* It is the logo of the publisher of the game, displayed on the game description page.<br />
* The width must be 150 px. The height can be anything. The image could be transparent.<br />
<br />
;publisher2.png (optional)<br />
* If the game has been co-published by 2 publishers, you should upload a second image named "publisher2.png" (same characteristic than the first one).<br />
<br />
== Game art ==<br />
<br />
You must upload in img directory all images of your game interface.<br />
<br />
=== Images loading ===<br />
<br />
'''Be careful''': by default, ALL images of your img directory are loaded on a player's browser when he loads the game. For this reason, don't let in your img directory images that are not useful, otherwise it's going to slowdown the game load.<br />
<br />
Note that you can tune the way images are loaded with Javascript methods "dontPreloadImage" and "ensureSpecificImageLoading" (see [[Game_interface_logic:_yourgamename.js|Game Interface Logic]]).<br />
<br />
=== Images format ===<br />
<br />
You can use 3 image format while building your game interface:<br />
;jpg images<br />
<br />
should be used for non-transparent images. Jpg are usually lighter than Pngs, so please choose Jpg for big pictures (ex: game board, cards) when you don't need transparency to accelerate game load.<br />
<br />
;png images<br />
<br />
should be used for transparent images.<br />
<br />
;gif images<br />
<br />
can be used for animated images. This is not recommended to use gif animated images as they can upset players, but for some specific interface element this could be useful.<br />
<br />
=== Use CSS Sprites ===<br />
<br />
To limit the number of images load and make the game load faster, you must use CSS sprites, ie you must gather several images in a single one.<br />
<br />
To learn more on CSS Sprites:<br />
* [http://www.w3schools.com/css/css_image_sprites.asp CSS sprites (W3C documentation)].<br />
* [[Game interface stylesheet: yourgamename.css]]</div>Sourisdudeserthttps://hu.doc.boardgamearena.com/index.php?title=Game_art:_img_directory&diff=457Game art: img directory2013-01-05T10:41:44Z<p>Sourisdudesert: /* Game art */</p>
<hr />
<div>== Requested images ==<br />
<br />
The following images are requested by BGA:<br />
<br />
;game_box.png<br />
* It is displayed on the main site on the game description page and when creating a table (280x280 px).<br />
* It should be an image of a physical copy of the game box as it appears in an online shop.<br />
* It is better to take the version of the game that is coherent with the game art used in the adaptation, and from the original publisher of the game.<br />
* The background of the image must be transparent.<br />
<br />
;game_icon.png<br />
<br />
* It is the icon displayed in the lists of games and tables (50x50 px).<br />
* This one should not be transparent, and shouldn't have a border (a black border will be add by BGA).<br />
* The objective of this icon is to make the game recognizable among the other games. A good idea is to take a part of the game cover that is distinctive (ex: the game title).<br />
<br />
;publisher.png<br />
* It is the logo of the publisher of the game, displayed on the game description page.<br />
* The width must be 150 px. The height can be anything. The image could be transparent.<br />
<br />
== Game art ==<br />
<br />
You must upload in img directory all images of your game interface.<br />
<br />
=== Images loading ===<br />
<br />
'''Be careful''': by default, ALL images of your img directory are loaded on a player's browser when he loads the game. For this reason, don't let in your img directory images that are not useful, otherwise it's going to slowdown the game load.<br />
<br />
Note that you can tune the way images are loaded with Javascript methods "dontPreloadImage" and "ensureSpecificImageLoading" (see [[Game_interface_logic:_yourgamename.js|Game Interface Logic]]).<br />
<br />
=== Images format ===<br />
<br />
You can use 3 image format while building your game interface:<br />
;jpg images<br />
<br />
should be used for non-transparent images. Jpg are usually lighter than Pngs, so please choose Jpg for big pictures (ex: game board, cards) when you don't need transparency to accelerate game load.<br />
<br />
;png images<br />
<br />
should be used for transparent images.<br />
<br />
;gif images<br />
<br />
can be used for animated images. This is not recommended to use gif animated images as they can upset players, but for some specific interface element this could be useful.<br />
<br />
=== Use CSS Sprites ===<br />
<br />
To limit the number of images load and make the game load faster, you must use CSS sprites, ie you must gather several images in a single one.<br />
<br />
To learn more on CSS Sprites:<br />
* [http://www.w3schools.com/css/css_image_sprites.asp CSS sprites (W3C documentation)].<br />
* [[Game interface stylesheet: yourgamename.css]]</div>Sourisdudesert