当前位置: 首页>>代码示例>>PHP>>正文


PHP game::update方法代码示例

本文整理汇总了PHP中game::update方法的典型用法代码示例。如果您正苦于以下问题:PHP game::update方法的具体用法?PHP game::update怎么用?PHP game::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在game的用法示例。


在下文中一共展示了game::update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: rollbackAndDie

     // teamAction
     // ------------------------------
 // ------------------------------
 // teamAction
 // ------------------------------
 case 'teamAction':
     // check inputs
     if (!isset($_GET['gameId']) or !isset($_GET['round']) or !isset($_GET['teamId']) or !isset($_GET['teamToken'])) {
         rollbackAndDie();
     }
     // get the game
     if (!$game->get($gameId)) {
         rollbackAndDie();
     }
     // update the game on the server side
     $game->update();
     // team valid?
     if (!$team->checkIfLegit($teamId, $teamToken)) {
         rollbackAndDie();
     }
     // is the team really in this game? get it
     if (!$team->get($gameId, $teamId)) {
         rollbackAndDie();
     }
     // from now on, before dying, we apply a penalty to this team if something goes wrong
     // can only add actions to a started game
     if ($game->getStatus() != Params::$gameStatus[1]) {
         punishAndDie($team, $game);
     }
     // check the round
     if ($round != $game->getRound()) {
开发者ID:jcaillon,项目名称:battle-code,代码行数:31,代码来源:BackEndController.php

示例2: addEventToGame

 public static function addEventToGame($game_id, $type, $first, $last, $score, $team)
 {
     $mysqli = new mysqli("classroom.cs.unc.edu", "hongkun", "CH@ngemenow99Please!hongkun", "hongkundb");
     /*check the connection*/
     if (mysqli_connect_errno()) {
         printf("Connection failed: %s\n", mysqli_connect_errno);
         exit;
     }
     // First: add the score to specific team, if team is found
     $teamSelected = $mysqli->query("select * from Game where (Team1 = '{$team}' || Team2 = '{$team}') && game_id = '{$game_id}'");
     if ($teamSelected->num_rows == 0) {
         header("HTTP/1.0 400 Bad Request");
         printMessageJSON("Bad Request, Team Not Match");
         exit;
     }
     $teamSelected = $teamSelected->fetch_row();
     $allAcore = [$teamSelected[1] => $teamSelected[3], $teamSelected[2] => $teamSelected[4]];
     if ($type == "fieldgoal") {
         $allAcore[$team] += 3;
     } else {
         if ($type == "passing") {
             $allAcore[$team] += 7;
         } else {
             if ($type == "rushing") {
                 $allAcore[$team] += 7;
             }
         }
     }
     // if the score is not match, exit();
     if ($allAcore[$team] != $score) {
         header("HTTP/1.0 400 Bad Request");
         printMessageJSON("Bad Request, Score Not Match");
         exit;
     }
     if ($allAcore[$teamSelected[1]] >= $allAcore[$teamSelected[2]]) {
         $winner = [$teamSelected[1] => $allAcore[$teamSelected[1]]];
         $loser = [$teamSelected[2] => $allAcore[$teamSelected[2]]];
     } else {
         $winner = [$teamSelected[2] => $allAcore[$teamSelected[2]]];
         $loser = [$teamSelected[1] => $allAcore[$teamSelected[1]]];
     }
     // Update the team score in Game Table.
     $gameUpdated = game::update($game_id, key($winner), key($loser), current($winner), current($loser));
     // Second: find the player in the team specified.
     // if it exists, return p_id, if not, insert it and return the p_id.
     $player_id = $mysqli->query("select player_id from Player where first_name = '{$first}' && last_name = '{$last}' && team_name = '{$team}'");
     if ($player_id->num_rows == 0) {
         $newPlayer = player::insert($first, $last, $team);
         $newPlayer = (array) $newPlayer;
         $player_id = intval($newPlayer["player_id"]);
     } else {
         $player_id = $player_id->fetch_row()[0];
     }
     // Use the p_id and game_id to find the event of the type,
     // if it exists, increase the number of the type
     // if not, insert the event.
     $eventSelected = $mysqli->query("select event_id from Event where p_id = '{$player_id}' && g_id = '{$game_id}'");
     $cnt = ["rushing" => 0, "passing" => 0, "fieldgoal" => 0, "passTo" => NULL];
     $cnt[$type]++;
     if ($eventSelected->num_rows == 0) {
         $event_id = event::insert($player_id, $game_id, $cnt["rushing"], $cnt["passing"], $cnt["fieldgoal"], $cnt["passTo"]);
     } else {
         $event_id = event::update($player_id, $game_id, $cnt["rushing"], $cnt["passing"], $cnt["fieldgoal"], $cnt["passTo"]);
     }
     // var_dump($event_id);
     $ids = [$game_id, $player_id];
     return $ids;
 }
开发者ID:HongkunGe,项目名称:footBallScoreManage,代码行数:68,代码来源:Game.php


注:本文中的game::update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。