public function testRegularGame() { $wallet = new Wallet(1000, 100); $cards = array(new Card(new Rank(4)), new Card(new Rank(8)), new Card(new Rank(3)), new Card(new Rank(Rank::QUEEN)), new Card(new Rank(5)), new Card(new Rank(Rank::ACE)), new Card(new Rank(3))); $game = new BlackjackGame(new TestDeck($cards)); $game->start(); $this->assertTrue($game->getState() == State::PLAYING); $game->hitUser(); $this->assertTrue($game->getState() == State::PLAYING_ACTIVE); $game->userStands(); $this->assertTrue($game->getState() == State::DEALER_WIN); $this->assertTrue($game->getDealerHand()->getScore() == 18); $this->assertTrue($game->getUserHand()->getScore() == 16); $wallet->reconcile($game); $this->assertTrue($wallet->getMoney() == 900); $wallet->reconcile($game); $this->assertTrue($wallet->getMoney() == 900); $cards = array(); for ($i = 0; $i < 100; $i++) { array_push($cards, new Card(new Rank(Rank::ACE))); } $game = new BlackjackGame(new TestDeck($cards)); $game->start(); $this->assertTrue($game->getState() == State::OFFER_INSURANCE); $game->buyInsurance(false); $this->assertTrue($game->getState() == State::PLAYING); $game->hitUser(); // 3 $this->assertTrue($game->getState() == State::PLAYING_ACTIVE); $game->hitUser(); // 4 $game->hitUser(); // 5 $game->hitUser(); // 6 $game->hitUser(); // 7 $game->hitUser(); // 8 $game->hitUser(); // 9 $game->hitUser(); // 10 $game->hitUser(); // 11/21 $game->userStands(); $this->assertTrue($game->getState() == State::USER_WIN); $this->assertTrue($game->getDealerHand()->getScore() == 17); $this->assertTrue($game->getUserHand()->getScore() == 21); $wallet->reconcile($game); $this->assertTrue($wallet->getMoney() == 1000); $wallet->reconcile($game); $this->assertTrue($wallet->getMoney() == 1000); }
if (!isset($_SESSION['wallet'])) { $resetwallet = true; } if ($resetwallet) { $wallet = new Wallet(1000, 50); $_SESSION['wallet'] = $wallet; } else { $wallet = $_SESSION['wallet']; } if (isset($_POST['SubmitWager']) && isset($_POST['Wager']) && $_POST['Wager'] <= MAX_WAGER && $_POST['Wager'] >= MIN_WAGER) { if (!isset($game) || $game == null || !State::isActive($game->getState())) { $wallet->setWager($_POST['Wager']); } } if ($deal) { $game = new BlackjackGame(); $_SESSION['game'] = $game; $game->start(); } else { $game = $_SESSION['game']; } $dealEnabled = 1; $hitEnabled = 0; $standEnabled = 0; $doubleEnabled = 0; $insuranceEnabled = 0; $wagerEnabled = 1; $gameOn = false; if (isset($game) && $game != null) { $gameOn = true; # check for user actions