tImplement basic initiative cards distribution - 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 f9a91007567fb5fe00bd6fe3ddd37801aeda3bd1
 (DIR) parent ef6bd543bb0bab6f8eb46de78ad3677d29848879
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Mon,  2 Mar 2020 21:36:42 +0100
       
       Implement basic initiative cards distribution
       
       Treat coins as a 5th resource and remove all "_max" resources that
       are useless. Players are given an initiative card based on their position
       in the game (instead of the opposite).
       
       Diffstat:
         M dbmodel.sql                         |       9 +++++----
         M hadarawgs.css                       |       3 +--
         M hadarawgs.game.php                  |      13 ++++++++++---
         M hadarawgs.js                        |       4 +---
         M hadarawgs_hadarawgs.tpl             |      15 +++++++++------
         M material.inc.php                    |      20 ++++++--------------
       
       6 files changed, 32 insertions(+), 32 deletions(-)
       ---
 (DIR) diff --git a/dbmodel.sql b/dbmodel.sql
       t@@ -12,9 +12,10 @@
        CREATE TABLE IF NOT EXISTS `playerboard` (
                `id` int(10) unsigned NOT NULL,
                `animal` varchar(255) NOT NULL,
       -        `income`   int(10) DEFAULT 0, `income_max`   int(10) DEFAULT 0,
       -        `military` int(10) DEFAULT 0, `military_max` int(10) DEFAULT 0,
       -        `culture`  int(10) DEFAULT 0, `culture_max`  int(10) DEFAULT 0,
       -        `food`     int(10) DEFAULT 0, `food_max`     int(10) DEFAULT 0,
       +        `coins`    int(10) DEFAULT 0,
       +        `income`   int(10) DEFAULT 0,
       +        `military` int(10) DEFAULT 0,
       +        `culture`  int(10) DEFAULT 0,
       +        `food`     int(10) DEFAULT 0,
                PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 (DIR) diff --git a/hadarawgs.css b/hadarawgs.css
       t@@ -29,13 +29,12 @@
                display: inline-block;
        }
        
       +.playerboard_coins    { padding: 2px; background-color: silver; }
        .playerboard_income   { padding: 2px; background-color: #ffff66; }
        .playerboard_military { padding: 2px; background-color: #ffaaaa; }
        .playerboard_culture  { padding: 2px; background-color: #aaaaff; }
        .playerboard_food     { padding: 2px; background-color: #aaffaa; }
        
       -.smalltext { font-size: 80%; }
       -
        /*
            Example of CSS sprites (a black token and a white token, 20x20px each, embedded in the same "tokens.png" 40x20px image):
        
 (DIR) diff --git a/hadarawgs.game.php b/hadarawgs.game.php
       t@@ -92,12 +92,19 @@ class hadarawgs extends Table
                        //self::initStat( 'player', 'player_teststat1', 0 );  // Init a player statistics (for all players)
        
                        // TODO: setup the initial game situation here
       -                $sql = "INSERT INTO playerboard (id, animal) VALUES";
       +                $sql = "INSERT INTO playerboard (id, animal, coins, income, military, culture, food) VALUES";
                        $values = array();
        
       +                $i=1;
                        foreach( $players as $player_id => $player ) {
       +                        $initiative = $this->init_cards[$i++];
       +                        $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')";
       +                        $values[] = "($player_id, '$animal', $coins, $income, $military, $culture, $food)";
                        }
        
                        $sql .= implode( $values, ',' );
       t@@ -162,7 +169,7 @@ class hadarawgs extends Table
                */
        
                function getPlayerBoard($player_id) {
       -                $sql = "SELECT id, animal, income, income_max FROM playerboard where id = $player_id";
       +                $sql = "SELECT id, animal FROM playerboard where id = $player_id";
                        return self::getCollectionFromDb($sql);
                }
        
 (DIR) diff --git a/hadarawgs.js b/hadarawgs.js
       t@@ -52,14 +52,12 @@ function (dojo, declare) {
                                for (var player_id in gamedatas.players) {
                                        var player = gamedatas.players[player_id];
                                        var board  = gamedatas.boards[player_id];
       -                                var tokens = ["income", "military", "culture", "food"];
       +                                var tokens = ["coins", "income", "military", "culture", "food"];
        
                                        // Set token values on each player board
                                        tokens.forEach(function (token) {
                                                var cur = document.getElementById(token +'_p' + player_id);
       -                                        var max = document.getElementById(token +'_max_p' + player_id);
                                                cur.innerHTML = board[token];
       -                                        max.innerHTML = board[token + '_max'];
                                        });
                                }
        
 (DIR) diff --git a/hadarawgs_hadarawgs.tpl b/hadarawgs_hadarawgs.tpl
       t@@ -6,17 +6,20 @@
                        <h3 style="color:#{PLAYER_COLOR}">{PLAYER_NAME}</h3>
                        <div class="icon_{PLAYER_ANIMAL}">animal</div>
                        <div class="playerboard_resources">
       +                        <div class="playerboard_coins">
       +                                <span id="coins_p{PLAYER_ID}">-</span>
       +                        </div>
                                <div class="playerboard_income">
       -                                <span id="income_p{PLAYER_ID}">-</span><span class="smalltext">/<span id="income_max_p{PLAYER_ID}">-</span></span>
       +                                <span id="income_p{PLAYER_ID}">-</span>
       +                        </div>
       +                        <div class="playerboard_food">
       +                                <span id="food_p{PLAYER_ID}">-</span>
                                </div>
                                <div class="playerboard_military">
       -                                <span id="military_p{PLAYER_ID}">-</span><span class="smalltext">/<span id="military_max_p{PLAYER_ID}">-</span></span>
       +                                <span id="military_p{PLAYER_ID}">-</span>
                                </div>
                                <div class="playerboard_culture">
       -                                <span id="culture_p{PLAYER_ID}">-</span><span class="smalltext">/<span id="culture_max_p{PLAYER_ID}">-</span></span>
       -                        </div>
       -                        <div class="playerboard_food">
       -                                <span id="food_p{PLAYER_ID}">-</span><span class="smalltext">/<span id="food_max_p{PLAYER_ID}">-</span></span>
       +                                <span id="culture_p{PLAYER_ID}">-</span>
                                </div>
                        </div>
                </div>
 (DIR) diff --git a/material.inc.php b/material.inc.php
       t@@ -19,18 +19,10 @@
         *
         */
        
       -
       -/*
       -
       -Example:
       -$this->card_types = array(
       -        1 => array( "card_name" => ...,
       -                                ...
       -                          )
       +$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, ),
        );
       -
       -*/
       -
       -
       -
       -