当前位置: 首页>>代码示例>>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;未经允许,请勿转载。