示例#1
0
 public static function getPromptCards($lastCardNos, $cardNos)
 {
     if (!$cardNos && !$cardNos[0]) {
         return false;
     }
     $lastCard = CardUtil::checkCards($lastCardNos);
     $lastType = $lastCard['type'];
     $minVal = $lastCard['minValue'];
     $num = $lastCard['num'];
     $_with = $lastCard['with'];
     if ($lastType == Constants::CARD_TYPE_KING) {
         return array();
     }
     $king = array();
     $_promptArr = array();
     if (in_array(161, $cardNos) && in_array(171, $cardNos)) {
         $king = array(161, 171);
     }
     $bombData = array('type' => Constants::CARD_TYPE_BOMB, 'num' => 4, 'minValue' => 2);
     $bombs = self::getPromptBaseCards($lastType == Constants::CARD_TYPE_BOMB ? $lastCard : $bombData, $cardNos);
     if (count($bombs) > 0) {
         $_promptArr = array_merge($_promptArr, $bombs);
     }
     if (count($king) > 0) {
         $_promptArr[] = $king;
     }
     if ($lastType == Constants::CARD_TYPE_FOUR_WITH) {
         $_lastCard = $lastCard;
         $_lastCard['type'] = Constants::CARD_TYPE_BOMB;
         $promptArr = self::getPromptBaseCards($_lastCard, $cardNos);
         $cardWith = array();
         if ($_lastCard['with'] == 1) {
             $singleWithData = array('type' => Constants::CARD_TYPE_SINGLE, 'num' => 1, 'minValue' => 2);
             $singleWith = self::getPromptBaseCards($singleWithData, $cardNos);
             if (count($singleWith) >= 2) {
                 foreach ($singleWith as $_single) {
                     $cardWith[] = $_single[0];
                     //客户端这里有问题
                     if (count($cardWith) == 2) {
                         break;
                     }
                 }
                 if (count($cardWith) != 2) {
                     return $_promptArr;
                 }
             } else {
                 return $_promptArr;
             }
         } elseif ($_lastCard['with'] == 2) {
             $doubleWithData = array('type' => Constants::CARD_TYPE_DOUBLE, 'num' => 1, 'minValue' => 2);
             $doubleWith = self::getPromptBaseCards($doubleWithData, $cardNos);
             if (count($doubleWith) >= 2) {
                 foreach ($doubleWith as $_double) {
                     $cardWith[] = $_double[0];
                     $cardWith[] = $_double[1];
                     if (count($cardWith) == 4) {
                         break;
                     }
                 }
                 if (count($cardWith) != 4) {
                     return $_promptArr;
                 }
             } else {
                 return $_promptArr;
             }
         }
         $len = count($promptArr);
         for ($i = 0; $i < $len; $i++) {
             $promptArr[$i] = array_merge($promptArr[$i], $cardWith);
         }
     } elseif ($lastType == Constants::CARD_TYPE_THREE_STRAIGHT_WITH) {
         $_lastCard = $lastCard;
         $_lastCard['type'] = Constants::CARD_TYPE_THREE_STRAIGHT;
         $promptArr = self::getPromptBaseCards($_lastCard, $cardNos);
         $cardWith = array();
         if ($_lastCard['with'] === 1) {
             $singleWithData = array('type' => Constants::CARD_TYPE_SINGLE, 'num' => 1, 'minValue' => 2);
             $singleWith = self::getPromptBaseCards($singleWithData, $cardNos);
             if (count($singleWith) >= $num) {
                 for ($i = 0; $i < count($singleWith); $i++) {
                     //确保所带的牌不是宿主牌
                     $cardWith[] = $singleWith[$i][0];
                     if (count($cardWith) == $num) {
                         break;
                     }
                 }
                 if (count($cardWith) != $num) {
                     return $_promptArr;
                 }
             } else {
                 return $_promptArr;
             }
         } elseif ($lastCard['with'] == 2) {
             $doubleWithData = array('type' => Constants::CARD_TYPE_DOUBLE, 'num' => 1, 'minValue' => 2);
             $doubleWith = self::getPromptBaseCards($doubleWithData, $cardNos);
             if (count($doubleWith) >= 2 * $num) {
                 foreach ($doubleWith as $_double) {
                     $cardWith[] = $_double[0];
                     $cardWith[] = $_double[1];
                     if (count($cardWith) == 2 * $num) {
                         break;
                     }
                 }
                 if (count($cardWith) != 2 * $num) {
                     return $_promptArr;
                 }
             } else {
                 return $_promptArr;
             }
         }
         $len = count($promptArr);
         for ($i = 0; $i < $len; $i++) {
             $promptArr[$i] = array_merge($promptArr[$i], $cardWith);
         }
     } elseif ($lastType == Constants::CARD_TYPE_THREE && $_with > 0) {
         $_lastCard = $lastCard;
         $_lastCard['type'] = Constants::CARD_TYPE_THREE;
         $promptArr = self::getPromptBaseCards($_lastCard, $cardNos);
         $cardWith = array();
         if ($_lastCard['with'] == 1) {
             $singleWithData = array('type' => Constants::CARD_TYPE_SINGLE, 'num' => 1, 'minValue' => 2);
             $singleWith = self::getPromptBaseCards($singleWithData, $cardNos);
             if (count($singleWith) >= $num) {
                 $cardWith[] = $singleWith[0][0];
                 if (count($cardWith) != 1) {
                     return $_promptArr;
                 }
             } else {
                 return $_promptArr;
             }
         } elseif ($lastCard['with'] == 2) {
             $doubleWithData = array('type' => Constants::CARD_TYPE_DOUBLE, 'num' => 1, 'minValue' => 2);
             $doubleWith = self::getPromptBaseCards($doubleWithData, $cardNos);
             if (count($doubleWith) >= 2) {
                 $cardWith[] = $doubleWith[0][0];
                 $cardWith[] = $doubleWith[0][1];
                 if (count($cardWith) != 2) {
                     return $_promptArr;
                 }
             } else {
                 return $_promptArr;
             }
         }
         $len = count($promptArr);
         for ($i = 0; $i < $len; $i++) {
             $promptArr[$i] = array_merge($promptArr[$i], $cardWith);
         }
     } else {
         $promptArr = self::getPromptBaseCards($lastCard, $cardNos);
     }
     if (count($bombs) > 0) {
         $promptArr = array_merge($promptArr, $bombs);
     }
     if (count($king) > 0) {
         $promptArr[] = $king;
     }
     return $promptArr;
 }
示例#2
0
 /**
  *  未对table进行存储
  * 下一个出牌
  * op 1手动操作了,0未手动操作
  */
 public function nextPlay($playCardNos = array(), $op = 0)
 {
     $currOpUid = $this->currOpUid;
     $this->lastOpUid = $currOpUid;
     $this->noPlayNums[$currOpUid] = isset($this->noPlayNums[$currOpUid]) ? $this->noPlayNums[$currOpUid] : 0;
     $this->noPlayNums[$currOpUid] = $op == 0 ? (int) $this->noPlayNums[$currOpUid] + 1 : 0;
     //托管,则自动出牌
     $currUidCards = $this->playerCards[$currOpUid];
     if (count($playCardNos) == 0) {
         if (count($this->lastCardNos) == 0) {
             if (CardUtil::checkCards($currUidCards)) {
                 $playCardNos = $currUidCards;
             } else {
                 end($currUidCards);
                 //取最小牌
                 $no = current($currUidCards);
                 $val = (int) ($no / 10);
                 foreach ($currUidCards as $cardNo) {
                     if ($val == (int) ($cardNo / 10)) {
                         $playCardNos[] = $cardNo;
                     }
                 }
             }
         } elseif ($op == 0) {
             $promptArrs = CardPrompt::getPromptCards($this->lastCardNos, $currUidCards);
             $promptArrs && $promptArrs[0] && ($playCardNos = $promptArrs[0]);
             rsort($playCardNos);
         }
     }
     $playCardData = CardUtil::checkPlayCards($this, $playCardNos);
     if ($playCardData && self::isExistCards($currUidCards, $playCardNos)) {
         //出牌成功,发送出牌信息-出牌玩家、所出的牌(无牌则为不出)
         //---客户端重置对手的手牌数量或重置自己的牌
         //是否炸弹、牌局倍数
         $re['isBomb'] = 0;
         $re['isSpring'] = 0;
         if ($playCardData['type'] == Constants::CARD_TYPE_BOMB || $playCardData['type'] == Constants::CARD_TYPE_KING) {
             $re['isBomb'] = 1;
             $this->multiple *= 2;
         }
         $currUidCards = array_diff($currUidCards, $playCardNos);
         $this->playerCards[$currOpUid] = $currUidCards;
         $this->lastCardNos = $playCardNos;
         $this->lastPlayCardUid = $currOpUid;
         $this->currOpUid = $this->getNextOpUid($currOpUid);
         $this->currUnPlayCnt = 0;
         if (count($currUidCards) == 0) {
             $this->tableStatus = Constants::TABLE_END;
             $this->currOpUid = $this->lastPlayCardUid;
             if ($currOpUid == $this->landlordUid) {
                 $isSpring = true;
                 foreach ($this->playerCards as $_uid => $cards) {
                     if ($_uid != $currOpUid && count($cards) < 17) {
                         $isSpring = false;
                     }
                 }
                 if ($isSpring) {
                     $re['isSpring'] = 1;
                     $this->multiple *= 2;
                 }
             }
             //没有手牌 获胜 结算,牌局销毁-进入匹配状态
             //是否春天
         }
         $re['playCardType'] = $playCardData;
         //玩家所出牌的类型
     } else {
         $this->currOpUid = $this->getNextOpUid($currOpUid);
     }
     $depositUid = 'no';
     //判断是否本轮结束,本轮结束,重置上次出牌并设置上次出牌玩家为当前出牌
     if ($this->currUnPlayCnt == 2) {
         $this->lastCardNos = array();
     }
     $this->currUnPlayCnt++;
     if ($op == 0 && $this->noPlayNums[$currOpUid] >= Constants::NO_PALY_NUM_TO_DEPOSIT) {
         if ($this->playerStatus[$currOpUid] != Constants::PLAYER_LEAVE) {
             $this->playerStatus[$currOpUid] = Constants::PLAYER_DEPOSIT;
         }
         //玩家未操作,状态为托管
         $depositUid = $currOpUid;
     }
     $this->recordTime = time();
     TableDao::addTable($this->tableId, $this);
     $re['type'] = 'play';
     $re['s'] = Constants::RESPONSE_SUCCESS;
     $re['leaveUid'] = $this->playerStatus[$currOpUid] == Constants::PLAYER_LEAVE ? $depositUid : 'no';
     $re['depositUid'] = $depositUid;
     //本轮托管玩家
     $re['lastCardNos'] = $this->lastCardNos;
     $re['lastPlayCardUid'] = $this->lastPlayCardUid;
     $re['currOpUid'] = $this->currOpUid;
     $re['lastOpUid'] = $this->lastOpUid;
     $re['lastOpCardNum'] = count($this->playerCards[$this->lastOpUid]);
     $re['tableSt'] = $this->tableStatus;
     $re['rTime'] = $this->recordTime;
     $re['multiple'] = $this->multiple;
     $uids = $this->uids;
     if ($this->tableStatus == Constants::TABLE_END) {
         $re['winUid'] = $this->lastPlayCardUid;
     }
     foreach ($uids as $_uid) {
         $_player = PlayerDao::getPlayer($_uid);
         if ($_player && $_player->tableId == $this->tableId) {
             Gateway::sendToUid($_uid, json_encode($re));
         }
     }
     if ($this->tableStatus == Constants::TABLE_END) {
         $this->tableOver($this->lastPlayCardUid);
     }
 }