コード例 #1
0
 private function loadWonders()
 {
     $wonders = json_decode(file_get_contents("cards/wonders.json"), true);
     foreach ($wonders as &$wonder) {
         foreach ($wonder as $side => &$value) {
             if ($side == 'name') {
                 continue;
             }
             if (isset($value['resource'])) {
                 $value['resource'] = Card::csvResources($value['resource'], true)[0];
             }
             foreach ($value['stages'] as &$stage) {
                 if (isset($stage['resource'])) {
                     $stage['resource'] = Card::csvResources($stage['resource'], false)[0];
                 }
                 $stage['requirements'] = Card::csvResources($stage['requirements'], false);
             }
         }
     }
     return $wonders;
 }
コード例 #2
0
ファイル: cards.php プロジェクト: julienreichel/sevenwonders
 function play(Player $user)
 {
     switch ($this->color) {
         case Card::RED:
             $user->military->add(intval($this->command));
             break;
         case Card::BLUE:
             // do nothing, calculate points later (see Player::calcPoints)
             break;
         case Card::YELLOW:
             if ($this->getAge() == 1) {
                 if (preg_match('/[0-9]/', $this->command)) {
                     $user->addCoins(intval($this->command));
                 } else {
                     $args = explode(' ', $this->command);
                     $directions = arrowsToDirection($args[0]);
                     $resources = Card::csvResources($args[1], false);
                     foreach ($resources as $resource) {
                         foreach ($directions as $dir) {
                             $user->addDiscount($dir, $resource);
                         }
                     }
                 }
             } elseif ($this->getAge() == 2) {
                 // check for yellow non-buyable resources
                 if (strpos($this->command, '/') !== false) {
                     $res = Card::csvResources($this->command, false);
                     $user->addResource($res[0]);
                 } else {
                     $args = explode(' ', $this->command);
                     $directions = arrowsToDirection($args[0]);
                     $coins = 0;
                     $color = $args[1];
                     $mult = intval($args[2]);
                     foreach ($directions as $dir) {
                         $pl = $user->neighbor($dir);
                         foreach ($pl->cardsPlayed as $c) {
                             if ($c->getColor() == $color) {
                                 $coins += $mult;
                             }
                         }
                     }
                     $user->addCoins($coins);
                 }
             } elseif ($this->getAge() == 3) {
                 $coins = $this->thirdAgeYellowCoins();
                 $color = $this->thirdAgeYellowColor();
                 // Be sure to count this yellow card for coin increase if
                 // we get coins per yellow card.
                 $coinsToGive = $color == Card::YELLOW ? $coins : 0;
                 if ($color == 'wonder') {
                     $coinsToGive = $coins * $user->wonderStage;
                 } else {
                     foreach ($user->cardsPlayed as $card) {
                         if ($card->getColor() == $color) {
                             $coinsToGive += $coins;
                         }
                     }
                 }
                 if ($coinsToGive > 0) {
                     $user->addCoins($coinsToGive);
                 }
             }
             break;
         case Card::GREEN:
             $user->science->add(intval($this->command));
             break;
         case Card::PURPLE:
             if ($this->getName() == 'Scientists Guild') {
                 $user->science->add(Science::ANY);
             }
             // none of these give coins or anything, so don't need to check
             // until the end
             break;
         case Card::BROWN:
         case Card::GREY:
             foreach (Card::csvResources($this->command, true) as $r) {
                 $user->addResource($r);
             }
             break;
     }
 }