/** * Deals cards to players based on hand size, * will deal entire deck if handSize is 0. Has scope for * dealing different sized hands as required * * @param int $handSize */ protected function deal($handSize = 0) { Talk::say('Dealing...'); if ($handSize == 0) { // If handSize is 0 then we'll deal all the cards to all players $counter = floor($this->deck->undealtCount() / count($this->players)); } else { if ($this->deck->undealtCount() >= count($this->players) * $handSize) { // Else if theres enough cards we'll deal the appropriate handSize $counter = $handSize; } else { // But if theres not enough cards we'll exit $counter = 0; } } // If we've got players if (!empty($this->players)) { // And the counter allows it while ($counter > 0) { // Deal a card to each player foreach ($this->players as $player) { $player->takeCard($this->deck->deal()); } // Decrement the counter $counter--; } } }
/** * Echos out a summary of current player card counts */ private function playerSummary() { foreach ($this->players as $player) { Talk::say($player->getName() . " now has " . $player->cardCount() . " cards", 0); } Talk::say('', 0); }