tInstantiate Desk module to manage all cards - hadarawgs - Hadara adaptation for boardgamearena.com
 (HTM) git clone git://git.z3bra.org/hadarawgs.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit c744db10a8c59a62de24720b59957bb8ecaf389f
 (DIR) parent 9778e860b1c282e098ad4bc083c6dbafd1f745e1
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Thu,  5 Mar 2020 13:17:08 +0100
       
       Instantiate Desk module to manage all cards
       
       Diffstat:
         M dbmodel.sql                         |       9 +++++++++
         M hadarawgs.game.php                  |      28 +++++++++++++++++++++++++---
         M material.inc.php                    |      25 +++++++++++++++++++------
       
       3 files changed, 53 insertions(+), 9 deletions(-)
       ---
 (DIR) diff --git a/dbmodel.sql b/dbmodel.sql
       t@@ -19,3 +19,12 @@ CREATE TABLE IF NOT EXISTS `playerboard` (
                `food`     int(10) DEFAULT 0,
                PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
       +
       +CREATE TABLE IF NOT EXISTS `card` (
       +  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
       +  `card_type` varchar(32) NOT NULL,
       +  `card_type_arg` int(10) NOT NULL,
       +  `card_location` varchar(32) NOT NULL,
       +  `card_location_arg` int(10) NOT NULL,
       +  PRIMARY KEY (`card_id`)
       +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
 (DIR) diff --git a/hadarawgs.game.php b/hadarawgs.game.php
       t@@ -39,6 +39,10 @@ class hadarawgs extends Table
                                //    "my_second_game_variant" => 101,
                                //      ...
                        ) );
       +
       +                // setup deck(s) to store all our cards
       +                $this->cards = self::getNew("module.common.deck");
       +                $this->cards->init("card");
                }
        
                protected function getGameName( )
       t@@ -95,21 +99,39 @@ class hadarawgs extends Table
                        $sql = "INSERT INTO playerboard (id, animal, coins, income, military, culture, food) VALUES";
                        $values = array();
        
       -                $i=1;
       +                shuffle($this->initiative);
                        foreach( $players as $player_id => $player ) {
       -                        $initiative = $this->init_cards[$i++];
       +                        $animal = array_shift($default_animals);
       +                        $initiative = array_shift($this->initiative);
                                $income = $initiative['income'];
                                $military = $initiative['military'];
                                $culture = $initiative['culture'];
                                $food = $initiative['food'];
                                $coins = $income + $initiative['coins'];
       -                        $animal = array_shift($default_animals);
                                $values[] = "($player_id, '$animal', $coins, $income, $military, $culture, $food)";
                        }
        
                        $sql .= implode( $values, ',' );
                        self::DbQuery( $sql );
        
       +                // Create a deck of setup cards
       +                $this->cards->createCards($this->card_setup, 'deck');
       +
       +                // Create all epoch cards and store them in a deck
       +                $cards = array();
       +                foreach ($this->card_types as $type) {
       +                        $n = ($type == "science") ? 14 : 10;
       +                        for ($epoch = 0; $epoch < 3; $epoch++)
       +                                $cards[] = array('type' => $type, 'type_arg' => $epoch, 'nbr' => $n);
       +                }
       +
       +                /*
       +                 * Put them all in the same deck. They will be
       +                 * moved to their respective 'type' deck at the
       +                 * beginning of each epoch
       +                 */
       +                $this->cards->createCards($cards, 'deck');
       +
                        // Activate first player (which is in general a good idea :) )
                        $this->activeNextPlayer();
        
 (DIR) diff --git a/material.inc.php b/material.inc.php
       t@@ -19,10 +19,23 @@
         *
         */
        
       -$this->init_cards = array(
       -        1 => array( "income" => 3, "military" => 2, "culture" => 1, "food" => 4, "coins" => 8, ),
       -        2 => array( "income" => 2, "military" => 1, "culture" => 3, "food" => 4, "coins" => 8, ),
       -        3 => array( "income" => 3, "military" => 2, "culture" => 2, "food" => 3, "coins" => 8, ),
       -        4 => array( "income" => 2, "military" => 1, "culture" => 2, "food" => 5, "coins" => 9, ),
       -        5 => array( "income" => 2, "military" => 2, "culture" => 1, "food" => 5, "coins" => 9, ),
       +
       +$this->card_types = array('setup', 'income', 'military', 'culture', 'food', 'science');
       +
       +// Setup cards, given at game start to players
       +$this->card_setup = array(
       +        array( 'type' => "initiative", 'type_arg' => 1, 'nbr' => 1),
       +        array( 'type' => "initiative", 'type_arg' => 2, 'nbr' => 1),
       +        array( 'type' => "initiative", 'type_arg' => 3, 'nbr' => 1),
       +        array( 'type' => "initiative", 'type_arg' => 4, 'nbr' => 1),
       +        array( 'type' => "initiative", 'type_arg' => 5, 'nbr' => 1),
       +);
       +
       +// Bonus given by the setup cards (corresponding to 'type_arg')
       +$this->initiative = array(
       +        1 => array("initiative" => 1, "income" => 3, "military" => 2, "culture" => 1, "food" => 4, "coins" => 8),
       +        2 => array("initiative" => 2, "income" => 2, "military" => 1, "culture" => 3, "food" => 4, "coins" => 8),
       +        3 => array("initiative" => 3, "income" => 3, "military" => 2, "culture" => 2, "food" => 3, "coins" => 8),
       +        4 => array("initiative" => 4, "income" => 2, "military" => 1, "culture" => 2, "food" => 5, "coins" => 9),
       +        5 => array("initiative" => 5, "income" => 2, "military" => 2, "culture" => 1, "food" => 5, "coins" => 9),
        );