Example #1
1
File: home.php Project: sherdog/wnd
 /**
  * PAGE: index
  * This method handles what happens when you move to http://yourproject/home/index (which is the default page btw)
  */
 public function index()
 {
     $redirected = false;
     //check if there is an error
     if ($_GET['error'] != '') {
         //load error page!
         die("<h1>Whoops, something went wrong, you can refresh to see if it fixes it otherwise check back later.</h1>");
     }
     if (isset($_GET['appSource'])) {
         $redirected = true;
         $appSource = (int) $_GET['appSource'];
     }
     if (!$redirected) {
         if (isset($_GET['id']) && $_GET['id'] != "") {
             $extraParameters['id'] = $_GET['id'];
         }
         if (isset($_GET['fbSource'])) {
             $extraParameters['appSource'] = $_GET['appSource'];
         }
         if (isset($_GET['traffic_source']) && $_GET['traffic_source'] != '') {
             $extraParameters['traffic_source'] = $_GET['traffic_source'];
         }
     }
     $signedRequest = null;
     if (isset($_POST['signed_request'])) {
         $signedRequest = self::parseSignedRequest($_POST['signed_request']);
     }
     Log::add('Signed request: ' . $signedRequest);
     //check if user_id
     if ($signedRequest === null) {
         //we need to get one!
         $url = Config::get('facebook.appurl') . "?" . http_build_query($_GET);
         header("location: " . $url);
         exit;
     }
     if (!isset($signedRequest['user_id']) || $signedRequest['user_id'] == '') {
         $redirectUrl = self::buildUrl($extraParameters);
         $oAuthUrl = "https://www.facebook.com/dialog/oauth?";
         $oAuthUrl .= http_build_query(array_filter(array('client_id' => Config::Get('facebook.appid'), 'redirect_uri' => self::buildUrl($extraParameters), 'scope' => 'user_friends,email')));
         die("<script>top.location.href = '" . $oAuthUrl . "';</script>");
     }
     $fbCurlReq = new Curl();
     $fbCurlReq->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $fbCurlReq->get('https://graph.facebook.com/me?access_token=' . $signedRequest['oauth_token']);
     if ($fbCurlReq->error) {
         Log::add('Error fb user profile ' . $fbCurlReq->error_code . ': ' . $fbCurlReq->error_message);
     } else {
         $dataArray = $fbCurlReq->response;
     }
     Log::add('dataArray = ' . print_r($dataArray, true));
     //check too see if this is a post :)
     $game = new Game();
     $game->loadGame((array) $dataArray, 'facebook', $extraParameters);
 }
Example #2
1
 private function playerWinsGame($combination, $playerToWin)
 {
     $player = $this->getDecoratedPlayerFromCombination($combination, $playerToWin);
     $game = new Game();
     $game->addPlayer($playerToWin, $player);
     foreach ($this->players as $label => $thisPlayer) {
         if ($label != $playerToWin) {
             $game->addPlayer($label, clone $thisPlayer);
         }
     }
     return $game->playGame() == $playerToWin;
 }
 function getListJuegoDetalleFactura($condicion = null, $parametros = array())
 {
     if ($condicion === null) {
         $condicion = "";
     } else {
         $condicion = "where {$condicion}";
     }
     $sql = "select ju.*, de.*, fa.*, cl.* from detalle de \r\n                    left join juego ju on ju.id_juego = de.id_juego \r\n                    left join factura fa on fa.num_factura = de.num_factura \r\n                    left join cliente cl on fa.id_cliente = cl.id_cliente  \r\n                {$condicion} ORDER BY cl.email, fa.fecha desc ";
     $this->bd->send($sql, $parametros);
     $r = array();
     $contador = 0;
     while ($fila = $this->bd->getRow()) {
         $juego = new Game();
         $juego->set($fila);
         $detalle = new Detalle();
         $detalle->set($fila, 8);
         $factura = new Factura();
         $factura->set($fila, 13);
         $cliente = new User();
         $cliente->set($fila, 16);
         $r[$contador]["juego"] = $juego;
         $r[$contador]["factura"] = $factura;
         $r[$contador]["detalle"] = $detalle;
         $r[$contador]["cliente"] = $cliente;
         $contador++;
     }
     return $r;
 }
Example #4
0
 public function updateAction()
 {
     $Game = new Game();
     $data = array('title' => $this->_request->title, 'description' => $this->_request->description, 'price' => $this->_request->price, 'no_times_played' => $this->_request->no_times_played, 'purchase_date' => $this->_request->purchase_date);
     $Game->update($data, "id = " . $this->_request->id);
     $this->_redirect('main/index');
 }
Example #5
0
 public function executeCreate(sfWebRequest $request)
 {
     $user = UserPeer::retrieveByPk($request->getParameter('username'));
     if (!$user) {
         $arr = array();
         $arr["result"] = false;
         $arr["message"] = "Invalid username";
         $this->renderText(json_encode($arr));
         return sfView::NONE;
     }
     $game = new Game();
     $game->setIsPublic($request->getParameter('public', 0));
     $game->setStartTime(time());
     $game->setIsActive(true);
     $game->setLatitude($request->getParameter('latitude'));
     $game->setLongitude($request->getParameter('longitude'));
     $game->save();
     $gameMember = new GameMember();
     $gameMember->setUserId($user->getId());
     $gameMember->setGameId($game->getId());
     $gameMember->setIsActive(true);
     $gameMember->save();
     $user->setCurrentGameId($game->getId());
     $this->updateUserLocation($user, $request);
     $arr = array();
     $arr["result"] = true;
     $arr["message"] = "Game created, game number is " . $game->getId() . ".  When others join, you will be assigned a target";
     $this->renderText(json_encode($arr));
     return sfView::NONE;
 }
Example #6
0
 public function addGameRow(Game $oGame, $includeField = true)
 {
     $oGame = Game::getByNefubId($oGame->nefub_id);
     $field = $oGame->field ? $oGame->field : 1;
     $gameType = $oGame->getCompetition()->getGender()->name . ' ' . $oGame->getCompetition()->getGenre()->name;
     $team1 = utf8_decode($oGame->getTeam1()->name);
     $team2 = utf8_decode($oGame->getTeam2()->name);
     if ($oGame->getFirstReferee()) {
         $oGame = new Game($oGame->getId());
         $oReferee = $oGame->getFirstReferee();
         $referee = utf8_decode($oReferee->getName());
         if (!$oReferee->getPerson()) {
             $referee .= ' (' . $oReferee->getTeam()->getCompetition()->getGender()->name;
             $referee .= ' ' . $oReferee->getTeam()->getCompetition()->getGenre()->name . ')';
         }
     } else {
         $referee = 'Onbekend';
     }
     $text = $oGame->getFormattedTime();
     $text .= "\t";
     $text .= $team1;
     $text .= "\t";
     $text .= $team2;
     $text .= "\n";
     $text .= $gameType;
     if ($includeField) {
         $text .= $field;
     }
     $this->section->addText($text, array('name' => 'Arial', 'size' => 10, 'bold' => false));
 }
Example #7
0
 public static function create($m_id, $g_name, $access_key)
 {
     F::i(_DBMS_SYS)->exec('INSERT INTO !prefix_games (g_id, m_id, g_name, g_access_key) VALUES (NULL, ?, ?, ?)', array($m_id, $g_name, $access_key));
     $game = new Game(F::i(_DBMS_SYS)->getInsertId());
     $game->insert($m_id);
     return $game;
 }
Example #8
0
 public function indexAction()
 {
     // ok lets show all their games here
     $Game = new Game();
     $games = $Game->findAll($this->sessionUserId);
     $this->view->games = $games;
 }
 public function __invoke()
 {
     $hitPoints = 103;
     $damagePoints = 9;
     $armourPoints = 2;
     $boss = new Boss($hitPoints, $damagePoints, $armourPoints);
     $game = new Game(new TurnTaker());
     $weapons = $this->getWeaponCollection();
     $armours = $this->getArmourCollection();
     $rings = $this->getRingCollection();
     $lowestCost = null;
     foreach ($weapons as $w => $weapon) {
         foreach ($armours as $a => $armour) {
             $permutations = $this->getRingPermutations(array_keys($rings));
             foreach ($permutations as $permutation) {
                 $boss->resurrect($hitPoints);
                 $r1 = $permutation[0];
                 $r2 = $permutation[1];
                 $player = new Player($weapon, $armour, $rings[$r1], $rings[$r2], 100);
                 /**
                  * @var $winner PlayerInterface
                  */
                 $winner = $game->play($player, $boss);
                 if (!$winner->isBoss()) {
                     $cost = $weapon->getCost() + $armour->getCost() + $rings[$r1]->getCost() + $rings[$r2]->getCost();
                     if (!$lowestCost || $cost < $lowestCost) {
                         $lowestCost = $cost;
                     }
                 }
             }
         }
     }
     $this->write("Lowest amount of gold to win: " . $lowestCost);
 }
Example #10
0
 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();
     }
 }
Example #11
0
 public function load()
 {
     //1055918
     $this->clear();
     $game = new Game();
     $game->setGametrackerId(1055918);
     $homeTeam = new GameTeam();
     $team = $this->CI->_team->findOneBySlug('miami-fl');
     $homeTeam->setTeam($team);
     $homeTeam->setScore(4);
     $homeTeam->setSide('home');
     $homeLineup = new Lineup();
     // <player name="Alfredo Rodriguez" shortname="Rodriguez, A" code="" uni="2" gp="1" gs="1" spot="1" pos="ss" atpos="ss" bats="R" throws="R" class="SR" bioid="395839" bioxml="http://grfx.cstv.com/bios/00/39/58/395839.xml">
     $player = $this->CI->_player->findOneBySlug('alfredo-rodriguez');
     $batter = new GameBatter();
     $batter->setPlayer($player);
     $batter->setNumber(2);
     $batter->setOrder(1);
     $batter->setPosition('SS');
     $batter->setAtBats(3);
     $batter->setRuns(0);
     $batter->setRunsBattedIn(1);
     $batter->setWalks(1);
     $batter->setHitByPitch(1);
     $batter->setGroundBalls(1);
     $batter->setFlyBalls(2);
     $batter->save();
     $homeLineup->addPlayer($batter);
     $homeTeam->setLineup($homeLineup);
     $game->setHome($homeTeam);
     print_r($game->getHome()->getLineup()->getPlayers());
     die;
     $division->save();
     print_r(sprintf("Created Division: %s (%s)\n", $division->getName(), $division->getId()));
 }
Example #12
0
 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('Not In');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust !');
     }
     $view = View::setFile('map', View::HTML_FILE);
     /**
      * Links
      */
     $result = F::i(_DBMS_SYS)->query('SELECT cou1.cou_name AS cou1, cou2.cou_name AS cou2 FROM !prefix_adjacent a, !prefix_countries cou1, !prefix_countries cou2 WHERE a.cou_id1 = cou1.cou_id AND a.cou_id2 = cou2.cou_id');
     while (($obj = $result->getObject()) != NULL) {
         $view->setGroupValues('adjacents', array('from' => $obj->cou1, 'to' => $obj->cou2));
     }
     $view->setValue('game', $game->g_id);
     $view->setValue('mode', isset($params['mode']) ? $params['mode'] : 'owner');
     $view->setValue('confirmed', $game->getPlayer(F::i('Session')->getMid())->p_ready);
     $view->setValue('step', $game->g_step);
     $view->setValue('m_id', F::i('Session')->getMid());
     return parent::setBody($view, '', TRUE);
 }
Example #13
0
 function display($id)
 {
     $game = new Game();
     $game->setId($id);
     $game = Query::getOne($game);
     return $game;
 }
Example #14
0
 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']);
 }
Example #15
0
 public function testSetCLock()
 {
     $game = new Game();
     $clock = $this->getClockMock();
     $game->setClock($clock);
     $this->assertSame($clock, $game->getClock());
     $this->assertTrue($game->hasClock());
 }
Example #16
0
 public function beforeSave()
 {
     if (preg_match('/^ん$/u', mb_substr($this->data['Word']['pronunciation'], -1, 1, 'UTF-8')) === 1) {
         App::import('Model', 'Game');
         $game = new Game();
         $game->save(array('id' => $this->data['Word']['game_id'], 'is_active' => false), false, array('is_active'));
     }
     return parent::beforeSave();
 }
 public function reload()
 {
     if ($this->isLoaded()) {
         $this->SQL->delete_game($this->Game->chat_id);
     }
     $this->Game = new Game();
     $this->Game->construct($this->chat_id, mt_rand(0, 5), 0);
     return $this->SQL->insert_game($this->Game);
 }
Example #18
0
 public function byGame()
 {
     $CRs = new CR($this->db);
     $this->f3->set('list', $CRs->byGame($this->f3->get('PARAMS.id')));
     $Game = new Game($this->db);
     $this->f3->set('game', $myGame = $Game->load(array('id=?', $this->f3->get('PARAMS.id'))));
     $this->f3->set('site_title', 'CRs de ' . $myGame['name'] . ' | CROTYpedia');
     $this->f3->set('view', 'cr/index.htm');
 }
Example #19
0
 public function displayTopPlayers()
 {
     echo "\n\t\t\t<span>\n\t\t\t<b>&middot;</b> <a href='" . MAIN_ROOT . "top-players/recruiters.php'>Recruiters</a>\n\t\t\t</span><br>\n\t\t\t";
     $hpGameObj = new Game($this->MySQL);
     $arrGames = $hpGameObj->getGameList();
     foreach ($arrGames as $gameID) {
         $hpGameObj->select($gameID);
         echo "\n\t\t\t\t<span>\n\t\t\t\t<b>&middot;</b> <a href='" . MAIN_ROOT . "top-players/game.php?gID=" . $gameID . "'>" . $hpGameObj->get_info_filtered("name") . "</a>\n\t\t\t\t</span><br>\n\t\t\t\t";
     }
 }
Example #20
0
 function actionAnswer()
 {
     $game = new Game();
     if (isset($_POST['answer']) && !empty($_POST['answer'])) {
         $answer = Functions::Encode($_POST['answer']);
         $answer_id = Functions::Encode($_POST['answer_id']);
         $model = $game->verifyAnswer($answer_id, $answer);
         print $model;
     }
 }
Example #21
0
 public function randomGame()
 {
     $id = $this->db->getValue("select id from chess_game where database_id=? order by rand()", $this->getId());
     if (isset($id)) {
         $game = new Game($id);
         return $game->read();
     } else {
         throw new LudoDBObjectNotFoundException("No games found in selected database(" . $this->getId() . ")");
     }
 }
 public function createMultiple($round)
 {
     foreach (Input::get('games') as $game) {
         $g = new Game();
         $g->round = $round->id;
         $g->slug = $game['slug'];
         $g->map = $game['map'];
         $g->save();
         App::make('ReportsController')->createMultiple($g, $game['players']);
     }
 }
 function test_checkType()
 {
     //Arrange
     $game = new Game();
     $input_1 = "rock";
     $input_2 = "scissors";
     //Act
     $result = $game->shoot($input_1, $input_2);
     // Assert
     $this->assertEquals("player 1", $result);
 }
Example #24
0
 static function load($id)
 {
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/datas/parties/" . $id) == false) {
         return null;
     }
     $content = unserialize(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/datas/parties/" . $id));
     $instance = new Game();
     $instance->setPlayers($content->getPlayers());
     $instance->setId($id);
     return $instance;
 }
 function test_threeTwoOne_paperBeatsRock()
 {
     // Arrange
     $test_Game = new Game();
     $input = 'paper';
     $input2 = 'rock';
     // Act
     $result = $test_Game->threeTwoOne($input, $input2);
     // Assert
     $this->assertEquals('player 1', $result);
 }
Example #26
0
 public function start()
 {
     // 1. The game contains
     $playerA = new Player('Player A');
     $playerB = new Player('Player B');
     $playerC = new Player('Player C');
     $playerD = new Player('Player D');
     // 4 players.
     $playerInstances = [$playerA, $playerB, $playerC, $playerD];
     $game = new Game($playerInstances);
     $game->start();
 }
 public function start(Player $player1, Player $player2, $loops)
 {
     for ($i = 1; $i <= $loops; $i++) {
         $game = new Game(new Board(), $player1, $player2);
         $winner = $game->start();
         if ($winner instanceof Player) {
             $this->results['wins'][$winner->getName()]++;
         } else {
             $this->results['undecided']++;
         }
     }
     return $this->getWinner();
 }
Example #28
0
 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('You are not part of this Game');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust !');
     }
     $game->reject(F::i('Session')->getMid());
     Tools::redirect('?action=current_games');
 }
 public function run()
 {
     $i = 0;
     foreach (array_keys(Config::get('devices')) as $device) {
         foreach (array_keys(Config::get('genres')) as $genre) {
             $game = new Game();
             $game->game_title = "game {$i}";
             $game->device = $device;
             $game->genre = $genre;
             $game->save();
             $i++;
         }
     }
 }
Example #30
0
 public static function update($id)
 {
     $params = $_POST;
     $attributes = array('id' => $id, 'name' => $params['name'], 'played' => $params['played'], 'published' => $params['published'], 'description' => $params['description']);
     // Alustetaan Game-olio käyttäjän syöttämillä tiedoilla
     $game = new Game($attributes);
     $errors = $game->errors();
     if (count($errors) > 0) {
         View::make('game/edit.html', array('errors' => $errors, 'attributes' => $attributes));
     } else {
         // Kutsutaan alustetun olion update-metodia, joka päivittää pelin tiedot tietokannassa
         $game->update();
         //Redirect::to('/game/' . $game->id, array('message' => 'Peliä on muokattu onnistuneesti!'));
     }
 }