コード例 #1
0
 public function onClose(WebSocketConnection $connection)
 {
     if ($this->isSubscribed($connection)) {
         $this->unsubscribe($connection);
     }
     $this->connections = $this->connections->filter(function ($c) use($connection) {
         return $c !== $connection;
     });
 }
コード例 #2
0
ファイル: Table.php プロジェクト: proof/blackjack-php-server
 public function __construct($seats = 5)
 {
     if ($seats <= 0) {
         throw new \LogicException('Table must have at least 1 seat');
     }
     $this->seats = new Vector();
     for ($seat = 0; $seat < $seats; $seat++) {
         $this->seats->pushBack(new TableSeat($seat, $this));
     }
     $this->id = md5(uniqid('', true));
 }
コード例 #3
0
 public function closeTable(Table $table)
 {
     $tableLoop = $this->getTableLoop($table);
     if ($tableLoop) {
         $tableLoop->cancel();
     }
     $this->logger->info('Closing table', ['id' => $table->getId()]);
     $this->tables = $this->tables->filter(function (Table $t) use($table) {
         return $t !== $table;
     });
 }
コード例 #4
0
ファイル: Deck.php プロジェクト: proof/blackjack-php-server
 public function restockDeck()
 {
     $this->cards = new Vector();
     $suit = [Card::SUIT_CLUBS, Card::SUIT_SPADES, Card::SUIT_HEARTS, Card::SUIT_DIAMONDS];
     foreach ($suit as $cardSuit) {
         for ($rank = Card::RANK_ACE; $rank <= Card::RANK_KING; $rank++) {
             if ($rank === 11) {
                 continue;
             }
             $this->cards->pushBack(new Card($rank, $cardSuit));
         }
     }
     $cards = clone $this->cards;
     for ($deck = 0; $deck < $this->decks; $deck++) {
         $this->cards->append($cards);
     }
 }
コード例 #5
0
 /**
  * @param string $class
  * @param int    $timeout
  *
  * @return Promise
  */
 public function waitOnMessage($class, $timeout = 3)
 {
     $deferred = new Deferred();
     $this->messageQueue[] = ['class' => $class, 'deferred' => $deferred];
     return \Blackjack\Promise\timeout($deferred->promise(), $timeout)->otherwise(function (\Exception $e) use($deferred) {
         $this->messageQueue = $this->messageQueue->filter(function ($entry) use($deferred) {
             return $entry['deferred'] !== $deferred;
         });
         return \React\Promise\reject($e);
     });
 }
コード例 #6
0
 private function handlePlayerDisconnection(Connection $connection)
 {
     $player = $connection->getPlayer();
     $seat = $player->getSeat();
     $playerConnection = $this->getPlayerConnection($player);
     $this->connections = $this->connections->filter(function ($c) use($playerConnection) {
         return $c !== $playerConnection;
     });
     $this->removePlayerFromSeat($seat, $assignBot = true);
     if (!$seat->getTable()->onlySeatedByBots() || count($this->tableManager->getTables()) === 1) {
         // Skip destroying table if this table is the last one standing
         // Or there's at least one computer bot connected via TCP
         return;
     }
     $this->destroyTable($seat->getTable());
 }
コード例 #7
0
ファイル: Hand.php プロジェクト: proof/blackjack-php-server
 /**
  * @param Card $card
  */
 public function addCard(Card $card)
 {
     $this->cards->pushBack($card);
 }
コード例 #8
0
 public function removeConnection(WebSocketConnection $connection)
 {
     $this->connections = $this->connections->filter(function ($c) use($connection) {
         return $c !== $connection;
     });
 }