本文整理汇总了PHP中Game类的典型用法代码示例。如果您正苦于以下问题:PHP Game类的具体用法?PHP Game怎么用?PHP Game使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Game类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* 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);
}
示例2: executeCreate
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;
}
示例3: getListJuegoDetalleFactura
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;
}
示例4: updateAction
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');
}
示例5: addGameRow
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));
}
示例6: create
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;
}
示例7: indexAction
public function indexAction()
{
// ok lets show all their games here
$Game = new Game();
$games = $Game->findAll($this->sessionUserId);
$this->view->games = $games;
}
示例8: __invoke
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);
}
示例9: 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();
}
}
示例10: load
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()));
}
示例11: getView
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);
}
示例12: display
function display($id)
{
$game = new Game();
$game->setId($id);
$game = Query::getOne($game);
return $game;
}
示例13: 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']);
}
示例14: testSetCLock
public function testSetCLock()
{
$game = new Game();
$clock = $this->getClockMock();
$game->setClock($clock);
$this->assertSame($clock, $game->getClock());
$this->assertTrue($game->hasClock());
}
示例15: beforeSave
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();
}