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(); } }
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']); }
public function testSetPlayers() { $game = new Game(); $players = $this->createPlayerStubs(); $game->addPlayer($players['white']); $game->addPlayer($players['black']); $this->assertEquals(2, count($game->getPlayers())); }
$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++) {