本文整理汇总了PHP中Game::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Game::create方法的具体用法?PHP Game::create怎么用?PHP Game::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game
的用法示例。
在下文中一共展示了Game::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getView
public function getView($params, $synchrone)
{
$form = new Form($this->fields, $params);
$title = '';
if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
$access_key = isset($params['access_key']) && !empty($params['access_key']) ? Tools::saltHash($params['access_key']) : 'NULL';
// Create Game
$game = Game::create(F::i('Session')->getMid(), $params['name'], $access_key);
Tools::redirect('?action=wait_game&game=' . $game->g_id);
} else {
// Generate form
$view = View::setFile('formular', View::HTML_FILE);
$errors = $form->getErrors();
// Errors in the filling
if (!empty($errors)) {
$view->setSwitch('form_errors', TRUE);
foreach ($errors as $field => $error) {
$view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error)));
}
}
$view->setValue('form', $form->getHTML(F::i('Lang')->getKey('Create'), '#', 'POST', 'tabbed_form'));
$title = F::i('Lang')->getKey('title_new_game');
}
return parent::setBody($view, $title);
}
示例2: doAddGame
public function doAddGame($data, Form $form)
{
$game = Game::create();
$game->ScoreTeamOne = $data['ScoreTeamOne'];
$game->ScoreTeamTwo = $data['ScoreTeamTwo'];
$game->write();
$redirectLink = $this->Link() . '?success=1';
return $this->redirect($redirectLink);
}
示例3: store
/**
* Store a newly created game in storage.
*
* @return Response
*/
public function store()
{
$validator = Validator::make($data = Input::all(), Game::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
Game::create($data);
return Redirect::route('games.index');
}
示例4: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('games', function (Blueprint $table) {
$table->increments('id');
$table->integer('winner_id')->unsigned()->index();
$table->foreign('winner_id')->references('id')->on('users')->onDelete('cascade');
$table->integer('status');
$table->integer('items');
$table->float('price');
$table->timestamp('started_at');
$table->timestamp('finished_at');
$table->json('won_items');
$table->integer('status_prize');
$table->string('rand_number');
$table->timestamps();
});
$rand_number = "0." . mt_rand(100000000, 999999999) . mt_rand(100000000, 999999999);
Game::create(['rand_number' => $rand_number]);
}
示例5: addGame
/**
* Attempts to save a game
*
* @return Game|null
*/
protected function addGame($form)
{
$siteConfig = SiteConfig::current_site_config();
$member = Member::currentUser();
$params = $this->request->allParams();
$fields = $form->Fields();
$id = $fields->dataFieldByName('ID')->Value();
$game = Game::get()->byID($id);
if (!$game) {
$game = Game::create();
}
$form->saveInto($game);
$game->FacilitatorID = $game->FacilitatorID ? $game->FacilitatorID : $member->ID;
$game->ParentID = $siteConfig->CurrentEventID;
try {
$game->write();
} catch (ValidationException $e) {
$form->sessionMessage($e->getResult()->message(), 'bad');
return;
}
return $game;
}
示例6: run
public function run()
{
$faker = Faker::create();
$characters = Character::all()->toArray();
$isk = PrizeType::where('name', '=', 'isk')->firstOrFail();
// Completed
foreach (range(1, 20) as $index) {
$initiator = $faker->randomElement($characters);
$winner = $faker->randomElement($characters);
$seats = $faker->numberBetween(4, 12);
$game = Game::create(['prize_type_id' => $isk->id, 'initiator_id' => $initiator['id'], 'winner_id' => $winner['id'], 'seats' => $seats, 'buy_in' => $faker->randomFloat(2, 10000, 50000000), 'deleted_at' => new DateTime()]);
$fulfilled = $index < 15 ? true : false;
$this->createPayout($game, $fulfilled);
$this->putPlayersInSeats($game, $seats, $initiator, $winner);
}
// In Progress
foreach (range(1, 5) as $index) {
$initiator = $faker->randomElement($characters);
$seats = $faker->numberBetween(4, 12);
$numberOfPlayers = $faker->numberBetween(0, $seats);
$game = Game::create(['prize_type_id' => $isk->id, 'initiator_id' => $initiator['id'], 'seats' => $seats, 'buy_in' => $faker->numberBetween(10000, 100000000) . 00]);
$this->putPlayersInSeats($game, $numberOfPlayers, $initiator);
}
}
示例7: array
require_once MB_ROOT . '/source/Game.class.php';
if (false) {
$debug = array();
$debug['tid'] = '1';
$debug['result'] = 'success';
$debug['from'] = 'return';
$debug['type'] = 'wechat';
$this->payResult($debug);
exit;
}
$user = $this->auth();
$id = $_GPC['actid'];
$id = intval($id);
$a = new Activity();
$activity = $a->getOne($id);
if (empty($activity) || $activity['type'] != 'game') {
exit('访问错误');
}
$g = new Game();
$order = array();
$order['activity'] = $activity['actid'];
$order['uid'] = $user['uid'];
$tid = $g->create($order);
if (is_error($tid)) {
exit('访问错误');
}
$trade = array();
$trade['tid'] = $tid;
$trade['title'] = "购买{$activity['tag']['label']} x1";
$trade['fee'] = $activity['tag']['price'];
$this->pay($trade);
示例8: create_object
public function create_object($data)
{
if (empty($data['victor'])) {
$data['victor'] = 0;
} else {
$data['victor'] = Agent::mapper()->create_object(array('id' => $data['victor'], 'alias' => $data['victor_agent_alias']));
unset($data['victor_alias']);
}
$game = Game::create($data, True);
$game->attach_mapper('Kill', Kill::mapper()->attach_storage(\Core\Storage::container()->get_storage('Kill')));
$game->attach_mapper('Agent', Agent::mapper()->attach_storage(\Core\Storage::container()->get_storage('Agent')));
foreach (array('start_date', 'end_date') as $f) {
$game[$f] = new \DateTime($game[$f]);
}
$game->invite_only = (int) $data['invite_only'];
$now = new \DateTime();
if ($game->start_date > $now) {
$game['joinable'] = True;
$game['active'] = False;
$game['state'] = 0;
} else {
if ($game->start_date < $now && $now < $game->end_date) {
$game['joinable'] = False;
$game['active'] = True;
$game['state'] = 1;
} else {
$game['joinable'] = False;
$game['active'] = False;
$game['state'] = 2;
}
}
return $game;
}
示例9: run
public function run()
{
DB::table('game')->delete();
//8e
Game::create(array('team1_id' => 1, 'team2_id' => 6, 'stage_id' => 4, 'team1_tmp_name' => '1A', 'team2_tmp_name' => '2B', 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1403971200)));
Game::create(array('team1_id' => 9, 'team2_id' => 15, 'stage_id' => 4, 'team1_tmp_name' => '1C', 'team2_tmp_name' => '2D', 'stage_game_num' => 2, 'date' => DateTime::createFromFormat('U', 1403985600)));
Game::create(array('team1_id' => 17, 'team2_id' => 22, 'stage_id' => 4, 'team1_tmp_name' => '1B', 'team2_tmp_name' => '2A', 'stage_game_num' => 3, 'date' => DateTime::createFromFormat('U', 1404144000)));
Game::create(array('team1_id' => 25, 'team2_id' => 32, 'stage_id' => 4, 'team1_tmp_name' => '1D', 'team2_tmp_name' => '2C', 'stage_game_num' => 4, 'date' => DateTime::createFromFormat('U', 1404158400)));
Game::create(array('team1_id' => 5, 'team2_id' => 2, 'stage_id' => 4, 'team1_tmp_name' => '1E', 'team2_tmp_name' => '2F', 'stage_game_num' => 5, 'date' => DateTime::createFromFormat('U', 1404057600)));
Game::create(array('team1_id' => 13, 'team2_id' => 12, 'stage_id' => 4, 'team1_tmp_name' => '1G', 'team2_tmp_name' => '2H', 'stage_game_num' => 6, 'date' => DateTime::createFromFormat('U', 1404072000)));
Game::create(array('team1_id' => 21, 'team2_id' => 19, 'stage_id' => 4, 'team1_tmp_name' => '1F', 'team2_tmp_name' => '2E', 'stage_game_num' => 7, 'date' => DateTime::createFromFormat('U', 1404230400)));
Game::create(array('team1_id' => 29, 'team2_id' => 26, 'stage_id' => 4, 'team1_tmp_name' => '1H', 'team2_tmp_name' => '2G', 'stage_game_num' => 8, 'date' => DateTime::createFromFormat('U', 1404244800)));
//Quarts
Game::create(array('stage_id' => 3, 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1404504000)));
Game::create(array('stage_id' => 3, 'stage_game_num' => 2, 'date' => DateTime::createFromFormat('U', 1404489600)));
Game::create(array('stage_id' => 3, 'stage_game_num' => 3, 'date' => DateTime::createFromFormat('U', 1404576000)));
Game::create(array('stage_id' => 3, 'stage_game_num' => 4, 'date' => DateTime::createFromFormat('U', 1404576000)));
//Demi
Game::create(array('stage_id' => 2, 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1404849600)));
Game::create(array('stage_id' => 2, 'stage_game_num' => 2, 'date' => DateTime::createFromFormat('U', 1404936000)));
//Finale
Game::create(array('stage_id' => 1, 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1405278000)));
//Petite Finale
Game::create(array('stage_id' => 5, 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1405195200)));
}
示例10: v14
public function v14()
{
// Regenerate cache
Cache::clear(false);
/*
* API
*/
// Copy bridge secret key to API private key
$bridge = json_decode($this->Setting->getOption('bridge'));
if (!empty($bridge) && $bridge->enabled && !empty($bridge->secret)) {
$api = array();
$api['enabled'] = 0;
$api['privateKey'] = $bridge->secret;
$this->Setting->setOption('api', json_encode($api));
// Disable bridge to make use users update their bridge plugin
$bridgeSettings = array();
$bridgeSettings['enabled'] = 0;
$bridgeSettings['url'] = $bridge->url;
$this->Setting->setOption('bridge', json_encode($bridgeSettings));
$this->Session->setFlash(__('Bridge has been disabled ! Be sure to use an updated version of your bridge plugin for MushRaider 1.4. If you don\'t you\'re gonna have a bad time !'), 'flash_important', array(), 'important');
}
/*
* Import
*/
// Add absolute path to games's logo field to prepare import functionallity
App::uses('Game', 'Model');
$GameModel = new Game();
$params = array();
$params['recursive'] = -1;
$params['fields'] = array('id', 'logo');
if ($games = $GameModel->find('all', $params)) {
foreach ($games as $game) {
if (!empty($game['Game']['logo']) && strpos($game['Game']['logo'], '/files/') === false) {
$toUpdate = array();
$toUpdate['id'] = $game['Game']['id'];
$toUpdate['logo'] = '/files/logos/' . $game['Game']['logo'];
$GameModel->create();
$GameModel->save($toUpdate);
}
}
}
/*
* Roles permissions
*/
// Add roles permissions
$rolesPermissions = array(array('title' => __('Full permissions'), 'alias' => 'full_permissions', 'description' => __('Like Chuck Norris, he can do anything. This overwrite every permissions')), array('title' => __('Limited admin access'), 'alias' => 'limited_admin', 'description' => __('Like Robin, he can do some things but not all (like driving the batmobile or change user role)')), array('title' => __('Can manage events'), 'alias' => 'manage_events', 'description' => __('Can create, edit and delete events. Can also manage the roster for each events')), array('title' => __('Can create templates'), 'alias' => 'create_templates', 'description' => __('Can create events templates')), array('title' => __('Can create reports'), 'alias' => 'create_reports', 'description' => __('Can create events reports')));
App::uses('RolePermission', 'Model');
$RolePermissionModel = new RolePermission();
foreach ($rolesPermissions as $rolesPermission) {
$RolePermissionModel->create();
$RolePermissionModel->save($rolesPermission);
}
// Add new roles permissions to existing roles
App::uses('Role', 'Model');
$RoleModel = new Role();
App::uses('RolePermissionRole', 'Model');
$RolePermissionRoleModel = new RolePermissionRole();
$RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('admin'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('full_permissions')));
$RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('limited_admin')));
$RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('manage_events')));
$RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_templates')));
$RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_reports')));
}
示例11: Game
<?php
require_once '../game.php';
$strategy = $_GET['strategy'];
$ships = $_GET['ships'];
try {
$game = new Game();
$game->create($strategy, $ships);
echo json_encode(["response" => true, "pid" => $game->getPlayerID()]);
} catch (GameException $e) {
echo json_encode(["response" => false, "reason" => $e->getMessage()]);
}
示例12: Game
require_once 'includes/inc.global.php';
// this has nothing to do with creating a game
// but I'm running it here to prevent long load
// times on other pages where it would be ran more often
GamePlayer::delete_inactive(Settings::read('expire_users'));
Game::delete_inactive(Settings::read('expire_games'));
Game::delete_finished(Settings::read('expire_finished_games'));
$Game = new Game();
if (isset($_POST['create'])) {
// make sure this user is not full
if ($GLOBALS['Player']->max_games && $GLOBALS['Player']->max_games <= $GLOBALS['Player']->current_games) {
Flash::store('You have reached your maximum allowed games !');
}
test_token();
try {
$game_id = $Game->create();
Flash::store('Game Created Successfully');
} catch (MyException $e) {
Flash::store('Game Creation FAILED !', false);
}
}
$color_selection = '';
foreach ($Game->get_avail_colors() as $color) {
$color_selection .= '<option class="' . strtolower(substr($color, 0, 3)) . '">' . ucfirst($color) . '</option>';
}
$meta['title'] = 'Create Game';
$meta['head_data'] = '
<script type="text/javascript" src="scripts/create.js"></script>
';
$hints = array('Create a game by filling out your desired game options.', '<span class="highlight">WARNING!</span><br />Games will be deleted after ' . Settings::read('expire_games') . ' days of inactivity.');
// make sure this user is not full
示例13: header
}
if (isset($_REQUEST['team1'])) {
$team1 = $_REQUEST['team1'];
} else {
header("HTTP/1.0 400 Bad Request");
print "Missing team1";
exit;
}
if (isset($_REQUEST['team2'])) {
$team2 = $_REQUEST['team2'];
} else {
header("HTTP/1.0 400 Bad Request");
print "Missing team2";
exit;
}
$new_game = Game::create($date, $team1, $team2);
if ($new_game == null) {
header("HTTP/1.0 500 Server Error");
print "Cannot create a new game";
exit;
}
header("Content-type: application/json");
print $new_game->getJSON();
exit;
} else {
if ($path_components[1] != "") {
$gid = $path_components[1];
$type = null;
$first = null;
$last = null;
$team = null;
示例14: run
public function run($args)
{
$this->server = new Websocket();
$this->games = array();
$that = $this;
// for use in the closures
$this->server->bind('open', function ($client_id) use($that) {
$ip = long2ip($that->server->wsClients[$client_id][6]);
$that->output('+ ' . $ip . ' (' . $client_id . ') connected', 'green');
});
$this->server->bind('message', function ($client_id, $msg, $msg_length, $binary) use($that) {
$ip = long2ip($that->server->wsClients[$client_id][6]);
if ($msg_length == 0) {
$that->server->wsClose($client_id);
return;
}
$action = json_decode($msg);
switch ($action->event) {
case 'login':
$username = str_replace(" ", "", trim($action->data->player_name));
$bad_usernames = array('system', 'admin', 'root');
if (in_array($username, $bad_usernames)) {
$that->send_to_one($client_id, 'login_error', array('msg' => 'That is an invalid username'));
} elseif (substr($username, 0, 1) == '@') {
$that->send_to_one($client_id, 'login_error', array('msg' => 'Twitter users are not yet implemented'));
} elseif (strlen($username) < 2 || strlen($username) > 15) {
$that->send_to_one($client_id, 'login_error', array('msg' => 'Username must be 2-15 characters in length'));
} else {
// Check if username is taken
// and build players array to send as user_list on the front end
$taken = false;
$players = array();
foreach ($that->server->wsClients as $id => $client) {
$name = $client[12]->name;
if ($name == $username) {
$taken = true;
break;
}
if ($name != NULL) {
$players[] = array('name' => $name);
}
}
if ($taken) {
$that->send_to_one($client_id, 'login_error', array('msg' => 'That username is already in use'));
} else {
$players[] = array('name' => $username, 'client_id' => $client_id);
$that->server->wsClients[$client_id][12]->name = $username;
$that->output('+ ' . $ip . ' (' . $client_id . ') identified as ' . $username, 'green');
$that->send_to_one($client_id, 'login_success', array('msg' => true));
if (count($that->games) > 0) {
$games_send = array();
foreach ($that->games as $key => $game) {
if ($game->state == 'WAITING') {
$games_send[] = array('id' => $game->id, 'started_by' => $game->started_by);
}
}
$that->send_to_one($client_id, 'games_list', $games_send);
}
// tell all players that this person is here
$that->send_to_all('lobby_chat', array('from' => 'system', 'msg' => $username . ' joined'));
$that->send_to_all('user_list', $players);
}
}
break;
case 'lobby_chat':
// TODO: add admin commands here...general commands too (uptime, etc)
$that->send_to_all('lobby_chat', array('from' => $that->server->wsClients[$client_id][12]->name, 'msg' => HTML::entities($action->data->msg)));
break;
case 'create_game':
if (!$that->server->wsClients[$client_id][12]->started_game) {
$g = new Game();
$g->create($that->server->wsClients[$client_id][12]->name);
$g->add_player($that->server->wsClients[$client_id][12], 0);
$that->games[$g->id] = $g;
$that->send_game_list();
$that->output('+ Game ' . $g->id . ' created!', 'green');
$that->send_to_all('lobby_chat', array('from' => 'system', 'msg' => $g->started_by . ' started a new game!'));
} else {
$that->send_to_one('lobby_chat', array('from' => 'system', 'msg' => 'You already have an open game!'));
}
break;
case 'join_game':
$game_id = $action->data->game;
$g = $that->games[$game_id];
$player_1 = $g->get_player_by_seat(0);
if ($player_1->name == $that->server->wsClients[$client_id][12]->name) {
$that->send_to_one($client_id, 'lobby_chat', array('from' => 'system', 'msg' => 'You are not allowed to join your own game'));
} else {
$g->add_player($that->server->wsClients[$client_id][12], 1);
$that->send_to_game($g, 'open_table', array('table_id' => $g->id, 'table_name' => $g->started_by . "'s Tournament"));
$g->game_log = array();
$g->start();
$that->send_to_game($g, 'game_log', array('game_id' => $g->id, 'msgs' => $g->game_log));
$g->game_log = array();
$that->render_game($g, true);
$that->games[$game_id] = $g;
$that->send_game_list();
$that->output('+ Game ' . $g->id . ' started!', 'white', true, 'green');
}
break;
//.........这里部分代码省略.........
示例15: header
if ($result != null) {
header("Content-type: application/json");
print $result->getJSON();
exit;
} else {
header("HTTP/1.0 400 Bad Request");
print "Username is already taken";
exit;
}
}
if ($path_components[1] == "game") {
$name = $path_components[2];
$aiName = $path_components[3];
$playerScore = $path_components[4];
$aiScore = $path_components[5];
$playerId = Player::findByUserName($name)->getID();
$aiId = Ai::findByName($aiName)->getID();
$result = Game::create($playerId, $aiId, $playerScore, $aiScore);
if ($result != null) {
header("Content-type: application/json");
print $result->getJSON();
exit;
} else {
header("HTTP/1.0 404 Bad Request");
print "Something went wrong";
exit;
}
}
}
}
}