当前位置: 首页>>代码示例>>PHP>>正文


PHP Card::hasPrereq方法代码示例

本文整理汇总了PHP中Card::hasPrereq方法的典型用法代码示例。如果您正苦于以下问题:PHP Card::hasPrereq方法的具体用法?PHP Card::hasPrereq怎么用?PHP Card::hasPrereq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Card的用法示例。


在下文中一共展示了Card::hasPrereq方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: calculateCost

 private function calculateCost(Card $card, $type)
 {
     if ($type == 'play') {
         // check for duplicates
         foreach ($this->cardsPlayed as $cardPlayed) {
             if ($cardPlayed->getName() == $card->getName()) {
                 return array();
             }
         }
         // check if it's a prerequisite for being free
         foreach ($this->cardsPlayed as $cardPlayed) {
             if ($card->hasPrereq($cardPlayed)) {
                 return array(array());
             }
         }
         $required = $card->getResourceCost();
     } else {
         // $type == 'wonder'
         // Can't over-build the wonder
         if ($this->wonderStage == count($this->wonder['stages'])) {
             return array();
         }
         $stage = $this->wonder['stages'][$this->wonderStage];
         $required = $stage['requirements'];
     }
     // Otherwise, we're going to have to pay for this card somehow
     $have = array();
     // We get all our resources for free
     foreach ($this->permResources as $resource) {
         $have[] = ResourceOption::me($resource);
     }
     // Add in all the left player's resources, factoring in discounts
     foreach ($this->leftPlayer->permResources as $resource) {
         if (!$resource->buyable()) {
             continue;
         }
         $have[] = ResourceOption::left($resource, $resource->discount($this->discounts['left']));
     }
     // Add in all the right player's resources, factoring discounts
     foreach ($this->rightPlayer->permResources as $resource) {
         if (!$resource->buyable()) {
             continue;
         }
         $have[] = ResourceOption::right($resource, $resource->discount($this->discounts['right']));
     }
     // Figure out how we can pay neighbors to satisfy our requirements
     $possible = Resource::satisfy($required, $have, $this->coins - $card->getMoneyCost());
     return $possible;
 }
开发者ID:ndorotte,项目名称:sevenwonders,代码行数:49,代码来源:player.php


注:本文中的Card::hasPrereq方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。