thadarawgs.game.php - hadarawgs - Hadara adaptation for boardgamearena.com
(HTM) git clone git://git.z3bra.org/hadarawgs.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
thadarawgs.game.php (10783B)
---
1 <?php
2 /**
3 *------
4 * BGA framework: © Gregory Isabelli <gisabelli@boardgamearena.com> & Emmanuel Colin <ecolin@boardgamearena.com>
5 * hadarawgs implementation : © Willy Goiffon <dev@z3bra.org>
6 *
7 * This code has been produced on the BGA studio platform for use on http://boardgamearena.com.
8 * See http://en.boardgamearena.com/#!doc/Studio for more information.
9 * -----
10 *
11 * hadarawgs.game.php
12 *
13 * This is the main file for your game logic.
14 *
15 * In this PHP file, you are going to defines the rules of the game.
16 *
17 */
18
19
20 require_once( APP_GAMEMODULE_PATH.'module/table/table.game.php' );
21
22 class hadarawgs extends Table
23 {
24 function __construct( )
25 {
26 // Your global variables labels:
27 // Here, you can assign labels to global variables you are using for this game.
28 // You can use any number of global variables with IDs between 10 and 99.
29 // If your game has options (variants), you also have to associate here a label to
30 // the corresponding ID in gameoptions.inc.php.
31 // Note: afterwards, you can get/set the global variables with getGameStateValue/setGameStateInitialValue/setGameStateValue
32 parent::__construct();
33
34 self::initGameStateLabels( array(
35 // "my_first_global_variable" => 10,
36 // "my_second_global_variable" => 11,
37 // ...
38 // "my_first_game_variant" => 100,
39 // "my_second_game_variant" => 101,
40 // ...
41 ) );
42
43 // setup deck(s) to store all our cards
44 $this->cards = self::getNew("module.common.deck");
45 $this->cards->init("card");
46 }
47
48 protected function getGameName( )
49 {
50 // Used for translations and stuff. Please do not modify.
51 return "hadarawgs";
52 }
53
54 /*
55 setupNewGame:
56
57 This method is called only once, when a new game is launched.
58 In this method, you must setup the game according to the game rules, so that
59 the game is ready to be played.
60 */
61 protected function setupNewGame( $players, $options = array() )
62 {
63 $gameinfos = self::getGameinfos();
64 $default_colors = $gameinfos['player_colors'];
65
66 // Create players
67 $sql = "INSERT INTO player (
68 player_id,
69 player_color,
70 player_canal,
71 player_name,
72 player_avatar) VALUES ";
73 $values = array();
74 foreach( $players as $player_id => $player ) {
75 $color = array_shift( $default_colors );
76 $values[] = "(
77 '$player_id',
78 '$color',
79 '" . $player['player_canal'] ."',
80 '" . addslashes( $player['player_name'] ) ."',
81 '" . addslashes( $player['player_avatar'] ) ."'
82 )";
83 }
84 $sql .= implode( $values, ',' );
85 self::DbQuery( $sql );
86 self::reattributeColorsBasedOnPreferences( $players, $gameinfos['player_colors'] );
87 self::reloadPlayersBasicInfos();
88
89 /************ Start the game initialization *****/
90
91 // Init global values with their initial values
92 //self::setGameStateInitialValue( 'my_first_global_variable', 0 );
93
94 // Init game statistics
95 // (note: statistics used in this file must be defined in your stats.inc.php file)
96 //self::initStat( 'table', 'table_teststat1', 0 ); // Init a table statistics
97 //self::initStat( 'player', 'player_teststat1', 0 ); // Init a player statistics (for all players)
98
99 // TODO: setup the initial game situation here
100 $sql = "INSERT INTO playerboard (id, coins, income, military, culture, food) VALUES";
101 $values = array();
102
103 shuffle($this->initiative);
104 foreach( $players as $player_id => $player ) {
105 $initiative = array_shift($this->initiative);
106 $income = $initiative['income'];
107 $military = $initiative['military'];
108 $culture = $initiative['culture'];
109 $food = $initiative['food'];
110 $coins = $income + $initiative['coins'];
111 $values[] = "($player_id, $coins, $income, $military, $culture, $food)";
112 }
113 $sql .= implode( $values, ',' );
114 self::DbQuery( $sql );
115
116 // Create a deck of setup cards
117 $this->cards->createCards($this->card_setup, 'deck');
118
119 // Create all epoch cards and store them in a deck
120 $cards = array();
121 foreach ($this->card_types as $type) {
122 $n = ($type == "science") ? 14 : 10;
123 for ($epoch = 0; $epoch < 3; $epoch++)
124 $cards[] = array('type' => $type, 'type_arg' => $epoch, 'nbr' => $n);
125 }
126
127 /*
128 * Put them all in the same deck. They will be
129 * moved to their respective 'type' deck at the
130 * beginning of each epoch
131 */
132 $this->cards->createCards($cards, 'deck');
133
134 // Activate first player (which is in general a good idea :) )
135 $this->activeNextPlayer();
136
137 /************ End of the game initialization *****/
138 }
139
140 /*
141 getAllDatas:
142
143 Gather all informations about current game situation (visible by the current player).
144
145 The method is called each time the game interface is displayed to a player, ie:
146 _ when the game starts
147 _ when a player refreshes the game page (F5)
148 */
149 protected function getAllDatas()
150 {
151 $result = array();
152
153 $current_player_id = self::getCurrentPlayerId(); // !! We must only return informations visible by this player !!
154
155 // Get information about players
156 // Note: you can retrieve some extra field you added for "player" table in "dbmodel.sql" if you need it.
157 $sql = "SELECT player_id id, player_score score FROM player ";
158 $result['players'] = self::getCollectionFromDb( $sql );
159
160 // TODO: Gather all information about current game situation (visible by player $current_player_id).
161 $result['boards'] = self::getCollectionFromDb('SELECT * FROM playerboard');
162
163 return $result;
164 }
165
166 /*
167 getGameProgression:
168
169 Compute and return the current game progression.
170 The number returned must be an integer beween 0 (=the game just started) and
171 100 (= the game is finished or almost finished).
172
173 This method is called each time we are in a game state with the "updateGameProgression" property set to true
174 (see states.inc.php)
175 */
176 function getGameProgression()
177 {
178 // TODO: compute and return the game progression
179
180 return 0;
181 }
182
183
184 //////////////////////////////////////////////////////////////////////////////
185 //////////// Utility functions
186 ////////////
187
188 /*
189 In this space, you can put any utility methods useful for your game logic
190 */
191
192 //////////////////////////////////////////////////////////////////////////////
193 //////////// Player actions
194 ////////////
195
196 /*
197 Each time a player is doing some game action, one of the methods below is called.
198 (note: each method below must match an input method in hadarawgs.action.php)
199 */
200
201 /*
202
203 Example:
204
205 function playCard( $card_id )
206 {
207 // Check that this is the player's turn and that it is a "possible action" at this game state (see states.inc.php)
208 self::checkAction( 'playCard' );
209
210 $player_id = self::getActivePlayerId();
211
212 // Add your game logic to play a card there
213 ...
214
215 // Notify all players about the card played
216 self::notifyAllPlayers( "cardPlayed", clienttranslate( '${player_name} plays ${card_name}' ), array(
217 'player_id' => $player_id,
218 'player_name' => self::getActivePlayerName(),
219 'card_name' => $card_name,
220 'card_id' => $card_id
221 ) );
222
223 }
224
225 */
226
227
228 //////////////////////////////////////////////////////////////////////////////
229 //////////// Game state arguments
230 ////////////
231
232 /*
233 Here, you can create methods defined as "game state arguments" (see "args" property in states.inc.php).
234 These methods function is to return some additional information that is specific to the current
235 game state.
236 */
237
238 /*
239
240 Example for game state "MyGameState":
241
242 function argMyGameState()
243 {
244 // Get some values from the current game situation in database...
245
246 // return values:
247 return array(
248 'variable1' => $value1,
249 'variable2' => $value2,
250 ...
251 );
252 }
253 */
254
255 //////////////////////////////////////////////////////////////////////////////
256 //////////// Game state actions
257 ////////////
258
259 /*
260 Here, you can create methods defined as "game state actions" (see "action" property in states.inc.php).
261 The action method of state X is called everytime the current game state is set to X.
262 */
263
264 /*
265
266 Example for game state "MyGameState":
267
268 function stMyGameState()
269 {
270 // Do some stuff ...
271
272 // (very often) go to another gamestate
273 $this->gamestate->nextState( 'some_gamestate_transition' );
274 }
275 */
276
277 //////////////////////////////////////////////////////////////////////////////
278 //////////// Zombie
279 ////////////
280
281 /*
282 zombieTurn:
283
284 This method is called each time it is the turn of a player who has quit the game (= "zombie" player).
285 You can do whatever you want in order to make sure the turn of this player ends appropriately
286 (ex: pass).
287
288 Important: your zombie code will be called when the player leaves the game. This action is triggered
289 from the main site and propagated to the gameserver from a server, not from a browser.
290 As a consequence, there is no current player associated to this action. In your zombieTurn function,
291 you must _never_ use getCurrentPlayerId() or getCurrentPlayerName(), otherwise it will fail with a "Not logged" error message.
292 */
293
294 function zombieTurn( $state, $active_player )
295 {
296 $statename = $state['name'];
297
298 if ($state['type'] === "activeplayer") {
299 switch ($statename) {
300 default:
301 $this->gamestate->nextState( "zombiePass" );
302 break;
303 }
304
305 return;
306 }
307
308 if ($state['type'] === "multipleactiveplayer") {
309 // Make sure player is in a non blocking status for role turn
310 $this->gamestate->setPlayerNonMultiactive( $active_player, '' );
311
312 return;
313 }
314
315 throw new feException( "Zombie mode not supported at this game state: ".$statename );
316 }
317
318 ///////////////////////////////////////////////////////////////////////////////////:
319 ////////// DB upgrade
320 //////////
321
322 /*
323 upgradeTableDb:
324
325 You don't have to care about this until your game has been published on BGA.
326 Once your game is on BGA, this method is called everytime the system detects a game running with your old
327 Database scheme.
328 In this case, if you change your Database scheme, you just have to apply the needed changes in order to
329 update the game database and allow the game to continue to run with your new version.
330
331 */
332
333 function upgradeTableDb( $from_version )
334 {
335 // $from_version is the current version of this game database, in numerical form.
336 // For example, if the game was running with a release of your game named "140430-1345",
337 // $from_version is equal to 1404301345
338
339 // Example:
340 // if( $from_version <= 1404301345 )
341 // {
342 // // ! important ! Use DBPREFIX_<table_name> for all tables
343 //
344 // $sql = "ALTER TABLE DBPREFIX_xxxxxxx ....";
345 // self::applyDbUpgradeToAllDB( $sql );
346 // }
347 // if( $from_version <= 1405061421 )
348 // {
349 // // ! important ! Use DBPREFIX_<table_name> for all tables
350 //
351 // $sql = "CREATE TABLE DBPREFIX_xxxxxxx ....";
352 // self::applyDbUpgradeToAllDB( $sql );
353 // }
354 // // Please add your future database scheme changes here
355 //
356 //
357
358
359 }
360 }