示例#1
0
 /**
  * Build site content depending on requested action.
  */
 protected function buildSite()
 {
     switch ($this->s->action) {
         case 'debug':
             $range = '99+, AQs+, 74s-73s, Th6h, Tc6c, Qh5h, 9s5s, 9c5c, Qh4h, 9d4d, 9h4h, 8s4s, 8c4c, 8d3d, 8h3h, Kc2c, 4d2d, 4s2s, AQo+, Ad4s, Ah4s, As4d, As4h, As4c, Ac4s, Ad3c, Ah3c, As3c, Ac3d, Ac3h, Ac3s, Ad2h, Ad2s, Ad2c, Ah2d, As2d, Ac2d, Jd7s, Jh7s, Js7d, Js7h, 9d6s, 9h6s, 9s6d, 9s6h, 8d6c, 8h6d, 8s6h, 8c6d, 7h5d, 7h5c, 7s5c, 7c5s, 6d5s, 6h5s, 6s5d, 6c5d';
             $content = '<h2>' . $range . '</h2>';
             $range = explode(',', $range);
             $objDeck = new PokerDeck();
             $objDeck->shuffle();
             $range = new PokerRange($range, $objDeck);
             $cards = $range->getRandomPair();
             $content .= '<p>Expanded: ' . implode(', ', $range->range) . '</p>';
             $content .= '<p>Pairs: ' . implode(', ', $range->pairs) . '</p>';
             $content .= '<p>Cards: ' . $cards[0]->shortname() . ' / ' . $cards[1]->shortname() . '</p>';
             parent::buildSite($content);
             break;
         case 'play':
             $tpl = new Template('poker');
             $tables = PokerTable::getAll();
             foreach ($tables as $key => $table) {
                 $table->active = PokerPlayer::getActivePlayer($key) !== FALSE ? TRUE : FALSE;
                 $table->free = $table->seats - count($table->players);
             }
             if (count($tables) == 0) {
                 $content = '<h2>Keine Pokertische vorhanden. <a href="poker/poker_table-list">Pokertisch anlegen</a>?</h2>';
             } else {
                 $tpl->assign('tables', $tables);
                 $tpl->assign('current', '');
                 //current($tables));
                 $content = $tpl->fetch('games.html');
             }
             parent::buildSite($content);
             break;
         case 'show':
             if ($this->s->params[0] != '') {
                 $tpl = new Template('poker');
                 $tpl->assign('idtable', $this->s->params[0]);
                 $content = $tpl->fetch('game.html');
             } else {
                 $content = 'Es wurde kein Pokertisch ausgewählt, der angezeigt werden könnte!';
             }
             parent::buildSite($content, true);
             break;
         case 'save':
             if ($this->s->params[0] == 'table' && $this->s->params[2] != 0) {
                 $new_actions = PokerTable::getTableActions($this->s->params[2], $this->s->params[1]);
                 $actions = $this->getActionLog($new_actions);
             } elseif (is_array($this->s->post['games'])) {
                 $actions = array();
                 foreach ($this->s->post['games'] as $key => $idgame) {
                     $game = Poker::getInstance($idgame);
                     $actions = array_merge($actions, $this->getActionLog($game->actions));
                 }
             }
             if (is_array($actions)) {
                 header("Expires: 0");
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Content-Type: text/plain; charset=utf-8");
                 header("Content-Description: File Transfer");
                 header("Content-Disposition: attachment; filename=poker_log.txt");
                 header("Content-Transfer-Encoding: binary");
                 foreach ($actions as $key => $value) {
                     echo $value . "\r\n";
                 }
             }
             break;
         case 'archive':
             if ($this->s->params[0] == '') {
                 $table = FALSE;
                 $content = '<h2>Spiele für ' . $this->s->user->realname . '</h2><h3>Um die Liste der Spiele auf einem bestimmten Tisch anzuzeigen, wähle „Spiele anzeigen“ in der <a href="poker/poker_table-list">Liste der Tische</a> aus.</h3>';
             } else {
                 $table = PokerTable::getInstance($this->s->params[0]);
                 $content = '<h2>Spiele am Tisch „' . $table->title . '“.</h2>';
             }
             $content .= $this->listGames($table);
             parent::buildSite($content);
             break;
     }
 }