public function show_Game() { if ($this->_myGame == null) { $this->error('Du spielst derzeit nicht!'); } switch ($this->get(1)) { case 'card': $this->_myCards[] = PlayingCards::getRandomCard(); $this->_myGame->user_cards = json_encode($this->_myCards); R::store($this->_myGame); $this->output('load', 'interact'); break; case 'finish': // check if dealer needs new card or not $dealerValue = 0; $dealerCards = array(); foreach ($this->_dealerCards as $c) { $dealerCards[] = PlayingCards::displayCard($c['card'], $c['color']); $dealerValue += ($dealerValue + $c['value'] > 21 and $c['card'] == 'a') ? 1 : $c['value']; } // now see if dealer has to draw more cards while ($dealerValue < 17) { $c = PlayingCards::getRandomCard(); $dealerValue += ($dealerValue + $c['value'] > 21 and $c['card'] == 'a') ? 1 : $c['value']; $this->_dealerCards[] = $c; $dealerCards[] = PlayingCards::displayCard($c['card'], $c['color']); } // calculate player value $playerValue = 0; $playerCards = array(); $playerSevenCount = 0; foreach ($this->_myCards as $c) { $playerCards[] = PlayingCards::displayCard($c['card'], $c['color']); if ($c['card'] == '7') { $playerSevenCount++; } // first count all the cards but no A-cards if ($c['card'] == 'a') { continue; } $playerValue += $c['value']; } foreach ($this->_myCards as $c) { // now count A-cards if ($c['card'] != 'a') { continue; } if ($playerValue + $c['value'] > 21) { $playerValue += 1; // if we would top 21 with 11, count as 1 } elseif ($playerValue + 1 < $dealerValue) { $playerValue += 11; // if counting as 1 would be smaller than // dealer count as 11 } else { $playerValue += 1; // count as 1 } } // now check who wins? $CardDisplay = '<h3>Deine Karten:</h3> ' . implode("", $playerCards) . ' <h3>Karten des Dealers:</h3> ' . implode("", $dealerCards); // player bust if ($playerValue > 21) { $this->output('maintext', '<b>BUST:</b> Deine Hand übersteigt 21 Punkte (' . $playerValue . ' P). <br /> Du verlierst deinen Einsatz ' . $CardDisplay); R::trash($this->_myGame); $this->output('options', array('interact' => 'Zurück')); return; } // triple seven if ($playerSevenCount == 3 && count($playerCards) == 3) { $winAmount = 1.5 * $this->_myGame->bid + $this->_myGame->bid; $this->output('maintext', '<b>TRIPLE SEVEN:</b> Du hast genau 3 Siebener auf der Hand! Du erhälst ' . formatCash($winAmount) . ' {money} ' . $CardDisplay); $this->user->cash += $winAmount; R::store($this->user); R::trash($this->_myGame); $this->output('options', array('interact' => 'Zurück')); return; } // dealer busts if ($dealerValue > 21) { $this->output('maintext', '<b>DEALER BUST:</b> Der Dealer hat mehr als 21 Punkte auf der Hand! <br /> Du bekommst ' . formatCash($this->_myGame->bid * 2) . ' {money} ' . $CardDisplay); $this->user->cash += $this->_myGame->bid * 2; R::store($this->user); R::trash($this->_myGame); $this->output('options', array('interact' => 'Zurück')); return; } // dealer has blackjack and player has blackjack too if ($dealerValue == 21 && count($dealerCards) == 2 && ($playerValue == 21 && count($playerCards) == 2) || $playerValue == $dealerValue) { $this->output('maintext', '<b>STAND OFF:</b> Der Dealer hat die gleichviele Punkte. Du bekommst deinen Einsatz zurück!' . $CardDisplay); $this->user->cash += $this->_myGame->bid; R::store($this->user); R::trash($this->_myGame); $this->output('options', array('interact' => 'Zurück')); return; } // player has blackjack if ($playerValue == 21 && count($playerCards) == 2) { $winAmount = 1.5 * $this->_myGame->bid + $this->_myGame->bid; $this->output('maintext', '<b>BLACK JACK:</b> Du hast einen Black Jack. Du erhälst ' . formatCash($winAmount) . ' {money}' . $CardDisplay); $this->user->cash += $winAmount; R::store($this->user); R::trash($this->_myGame); $this->output('options', array('interact' => 'Zurück')); return; } // compare points if ($playerValue > $dealerValue) { $this->output('maintext', '<b>EVEN MONEY:</b> Du gewinnst mit ' . $playerValue . ' Punkten gegen den Dealer (' . $dealerValue . ' Punkte)! <br /> Du erhälst ' . formatCash($this->_myGame->bid * 2) . ' {money}' . $CardDisplay); $this->user->cash += $this->_myGame->bid * 2; R::store($this->user); R::trash($this->_myGame); $this->output('options', array('interact' => 'Zurück')); return; } // dealer wins $this->output('maintext', 'Du verlierst gegen den Dealer. Du hast ' . $playerValue . ' Punkte, der Dealer ' . $dealerValue . ' Punkte. Du verlierst deinen Einsatz. ' . $CardDisplay); R::trash($this->_myGame); $this->output('options', array('interact' => 'Zurück')); break; default: $this->error('Invalid ACTION!'); break; } }