當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Game::getPlayers方法代碼示例

本文整理匯總了PHP中Game::getPlayers方法的典型用法代碼示例。如果您正苦於以下問題:PHP Game::getPlayers方法的具體用法?PHP Game::getPlayers怎麽用?PHP Game::getPlayers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Game的用法示例。


在下文中一共展示了Game::getPlayers方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getView

 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if ($game->g_step > 0) {
             throw new Exception('Game already launched');
         }
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('You are not in this game');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust ! : ' . $e);
     }
     if ($synchrone) {
         $view = View::setFile('wait_game', View::HTML_FILE);
         $view->setValue('u_js', '?action=wait_game&game=' . $game->g_id);
         $view->setValue('u_leave', '?action=leave_game&game=' . $game->g_id);
         $view->setValue('game', stripslashes($game->g_name));
         if ($game->m_id == F::i('Session')->getMid()) {
             $view->setSwitch('creator', TRUE);
             $view->setValue('u_launch', '?action=launch_game&game=' . $game->g_id);
         }
         return parent::setBody($view, F::i('Lang')->getKey('title_wait_game'));
     } else {
         $view = View::setFile('wait_game', View::JSON_FILE);
         $players = $game->getPlayers();
         for ($i = 0; $i < count($players); $i++) {
             $view->setGroupValues('players', array('name' => $players[$i]->m_login, 'color' => $players[$i]->col_code, 'col_name' => $players[$i]->col_name));
         }
         return $view->getContent();
     }
 }
開發者ID:Korko,項目名稱:RiskOnline,代碼行數:33,代碼來源:wait_game.php

示例2: getView

 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if ($game->g_step > 0) {
             throw new Exception('Game already launched');
         }
         if ($game->m_id != F::i('Session')->getMid()) {
             throw new Exception('You are not the owner of this game !');
         }
         if ($game->getNumPlayers() == 1) {
             throw new Exception('Cannot launch a game with a single player');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust !');
     }
     // Give countries to players
     /*
      * 42 countries
      * /2 => 21
      * /3 => 14
      * /4 => 10.5 (10 + 2)
      * /5 => 8.4 (8 + 2)
      * /6 => 7
      * /7 => 6
      * /8 => 5.25 (5 + 2)
      * /9 => 4.67 (4 + 6)
      * /10 => 4.2 (4 + 2)
      */
     $players = $game->getPlayers();
     $count_players = count($players);
     $result = F::i(_DBMS_SYS)->query('SELECT cou_id FROM !prefix_countries');
     $countries = array();
     while (($obj = $result->getObject()) != NULL) {
         $countries[] = $obj->cou_id;
     }
     $count_countries = count($countries);
     $countries_per_player = intval($count_countries / $count_players);
     shuffle($countries);
     $lands = array_chunk($countries, $countries_per_player);
     // What to do with the last countries ? Give...
     $remaining = array();
     if (count($lands) > $count_players) {
         $remaining = $lands[$count_players];
     }
     shuffle($players);
     for ($i = 0; $i < count($remaining); $i++) {
         $lands[$i][] = $remaining[$i];
     }
     // Save and Go to step 1
     for ($i = 0; $i < $count_players; $i++) {
         for ($j = 0; $j < count($lands[$i]); $j++) {
             F::i(_DBMS_SYS)->exec('INSERT INTO !prefix_lands (g_id, cou_id, m_id) VALUES (?, ?, ?)', array($params['game'], $lands[$i][$j], $players[$i]->m_id));
         }
     }
     $game->nextStep();
     Tools::redirect('?action=play&game=' . $params['game']);
 }
開發者ID:Korko,項目名稱:RiskOnline,代碼行數:59,代碼來源:launch_game.php

示例3: testSetPlayers

 public function testSetPlayers()
 {
     $game = new Game();
     $players = $this->createPlayerStubs();
     $game->addPlayer($players['white']);
     $game->addPlayer($players['black']);
     $this->assertEquals(2, count($game->getPlayers()));
 }
開發者ID:hotfics,項目名稱:lichess-old,代碼行數:8,代碼來源:GameTest.php

示例4: array

$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get('/', function () use($app) {
    return $app['twig']->render('go_fish.html.twig', array('games' => Game::getAll()));
});
$app->get('/add_players', function () use($app) {
    return $app['twig']->render('add_players.html.twig');
});
$app->post('/created_players', function () use($app) {
    $new_game = new Game();
    $new_players = new Player();
    $player1 = $_POST['player1'];
    $player2 = $_POST['player2'];
    $new_players->setName1($player1);
    $new_players->setName2($player2);
    $new_game->setPlayers($new_players);
    $current_players = $new_game->getPlayers();
    $new_game->save();
    $new_players->save();
    return $app['twig']->render('created_players.html.twig', array('newplayers' => $current_players));
});
$app->get('/add_player_one_cards', function () use($app) {
    return $app['twig']->render('add_player_one_cards.html.twig');
});
$app->post('/player_one_hand', function () use($app) {
    $active_game = Game::getAll();
    $active_players = Player::getAll();
    $current_players = $active_players[0]->getPlayers();
    $current_score = $active_players[0]->getScore1();
    $cards = $current_players->getCards();
    $current_hand = array();
    for ($i = 0; $i <= 4; $i++) {
開發者ID:eddieduro,項目名稱:go-fish-PHP,代碼行數:31,代碼來源:app.php


注:本文中的Game::getPlayers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。