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


PHP game::read方法代码示例

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


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

示例1: process

 public function process()
 {
     $user = user::getInstance();
     $db = db::getInstance();
     include './models/game.class.php';
     include './models/grid.class.php';
     // récupérer le gameid
     $this->gameid = isset($_REQUEST['gameid']) ? intval($_REQUEST['gameid']) : false;
     if ($this->gameid === false) {
         trigger_error('Game not found', E_USER_ERROR);
     }
     // lecture de l'objet game
     $game = new game();
     $game->read($this->gameid);
     // création d'une nouvelle grille
     $gridtype = GRIDTYPE_ALLWORDS;
     $grid = new grid();
     $gridid = $grid->create($gridtype);
     // ajout de la grille au game
     $game->assign_grid($gridid);
     $game->start_grid($gridid);
     // enrichissement du retour json
     $res = $grid->get();
     $res->gameid = $this->gameid;
     $res->gametype = GAMETYPE_PRACTICE_ALLWORDS;
     header('Content-Type: application/json');
     echo json_encode($res);
     die;
 }
开发者ID:ryu38000,项目名称:Magic-Word-game,代码行数:29,代码来源:game.launch.practice.allwords.class.php

示例2: process

 public function process()
 {
     $db = db::getInstance();
     $user = user::getInstance();
     include './models/game.class.php';
     // récupérer le gameid si il existe
     $game = false;
     $this->gameid = isset($_REQUEST['gameid']) ? intval($_REQUEST['gameid']) : false;
     if ($this->gameid !== false) {
         $game = new game();
         if (!$game->read($this->gameid)) {
             $this->gameid = false;
             trigger_error('Game not found!', E_USER_ERROR);
         }
         if (!isset($game->userids[$user->id])) {
             $this->gameid = false;
             trigger_error('Not your game!', E_USER_ERROR);
         }
     }
     /*// fermer toute grille en cours pour cet utilisateur
     		$sql = 'UPDATE gamesstatus
     					SET gridstatus = ' . intval(GRIDSTATUS_FINISHED) . '
     					WHERE userid = ' . intval($user->id) . '
     						AND gridstatus = ' . intval(GRIDSTATUS_STARTED);
     		$db->query($sql);*/
     // déterminer le type de partie à partir du mode
     $gametype = false;
     switch ($this->mode) {
         case 'game.launch.practice.allwords':
             $gametype = GAMETYPE_PRACTICE_ALLWORDS;
             break;
         case 'game.launch.practice.longest':
             $gametype = GAMETYPE_PRACTICE_LONGEST;
             break;
         case 'game.launch.practice.constraints':
             $gametype = GAMETYPE_PRACTICE_CONSTRAINTS;
             break;
         case 'game.launch.practice.full':
             $gametype = GAMETYPE_PRACTICE_FULL;
             break;
     }
     // créer une nouvelle partie
     if (!$this->gameid) {
         $userids = array($user->id);
         $game = new game();
         $this->gameid = $game->create($userids, $gametype, $user->get_lang());
     }
     return $this->display();
 }
开发者ID:ryu38000,项目名称:Magic-Word-game,代码行数:49,代码来源:game.launch.practice.main.class.php

示例3: process

    public function process()
    {
        $db = db::getInstance();
        $user = user::getInstance();
        include './models/game.class.php';
        include './models/grid.class.php';
        // récupérer le gameid
        $this->gameid = isset($_REQUEST['gameid']) ? intval($_REQUEST['gameid']) : false;
        if ($this->gameid === false) {
            trigger_error('Game not found', E_USER_ERROR);
        }
        // lecture de l'objet game
        $game = new game();
        $game->read($this->gameid);
        // lire les grilles terminées pour trouver le prochain type de grille
        $sql = 'SELECT COUNT(gridid) AS count_gridid
					FROM gamesstatus
					WHERE gameid = ' . intval($this->gameid) . '
						AND userid = ' . intval($user->id) . '
						AND gridstatus = ' . intval(GRIDSTATUS_FINISHED);
        $result = $db->query($sql);
        $grid_count = ($row = $result->fetch_assoc()) ? intval($row['count_gridid']) : 0;
        // déterminer le prochain type de grille
        switch ($grid_count) {
            case 0:
                $gridtype = GRIDTYPE_ALLWORDS;
                break;
            case 1:
                $gridtype = GRIDTYPE_LONGEST;
                break;
            case 2:
                $gridtype = GRIDTYPE_CONSTRAINTS;
                break;
        }
        // création d'une nouvelle grille
        $grid = new grid();
        $gridid = $grid->create($gridtype);
        // ajout de la grille au game
        $game->assign_grid($gridid);
        $game->start_grid($gridid);
        $res = $grid->get();
        $res->gameid = $this->gameid;
        $res->gametype = GAMETYPE_PRACTICE_FULL;
        header('Content-Type: application/json');
        echo json_encode($res);
        die;
    }
开发者ID:ryu38000,项目名称:Magic-Word-game,代码行数:47,代码来源:game.launch.practice.full.class.php

示例4: process

    public function process()
    {
        $db = db::getInstance();
        $user = user::getInstance();
        include './models/game.class.php';
        include './models/grid.class.php';
        // récupérer le gameid
        $this->gameid = isset($_REQUEST['gameid']) ? intval($_REQUEST['gameid']) : false;
        if ($this->gameid === false) {
            trigger_error('Game not found', E_USER_ERROR);
        }
        // lecture de l'objet game
        $game = new game();
        $game->read($this->gameid);
        // lire les grilles terminées pour trouver le prochain type de grille
        $grid_counts = array();
        $last_grid = 0;
        $sql = 'SELECT userid, COUNT(gridid) AS count_gridid
					FROM gamesstatus
					WHERE gameid = ' . intval($this->gameid) . '
						AND gridstatus = ' . intval(GRIDSTATUS_FINISHED) . '
					GROUP BY userid';
        $result = $db->query($sql);
        while ($row = $result->fetch_assoc()) {
            $grid_counts[intval($row['userid'])] = intval($row['count_gridid']);
            if (intval($row['count_gridid']) > $last_grid && intval($row['userid']) != $user->id) {
                $last_grid = intval($row['count_gridid']);
            }
        }
        if (isset($grid_counts[$user->id])) {
            if ($grid_counts && $last_grid < intval($grid_counts[$user->id])) {
                trigger_error('Wait for the other!', E_USER_ERROR);
            }
            $grid_count = $grid_counts ? intval($grid_counts[$user->id]) : 0;
        } else {
            $grid_count = 0;
        }
        // déterminer le prochain type de grille
        $gridtype = false;
        switch ($grid_count) {
            case 0:
                $gridtype = GRIDTYPE_ALLWORDS;
                break;
            case 1:
                $gridtype = GRIDTYPE_LONGEST;
                break;
            case 2:
                $gridtype = GRIDTYPE_CONSTRAINTS;
                break;
            default:
                trigger_error('Game over!', E_USER_ERROR);
                break;
        }
        // vérifier si l'autre adversaire est en train de créer une grille
        $sql = ' SELECT *
					FROM gamesusers
					WHERE gameid = ' . intval($this->gameid);
        $result = $db->query($sql);
        $row = $result->fetch_assoc();
        $request = $row['request'];
        // lire les grilles existantes pour ce type de grille
        $sql = 'SELECT *
					FROM gamesstatus gs, grids g
					WHERE gs.gameid = ' . intval($this->gameid) . '
						AND gs.userid = ' . intval($user->id) . '
						AND gs.gridstatus = ' . intval(GRIDSTATUS_ASSIGNED) . '
						AND g.gridid = gs.gridid
						AND g.gridtype = ' . intval($gridtype);
        $result = $db->query($sql);
        $gridid = ($row = $result->fetch_assoc()) ? intval($row['gridid']) : false;
        if ($request == 1) {
            // lire les grilles existantes pour ce type de grille
            $sql = 'SELECT *
						FROM gamesstatus gs, grids g
						WHERE gs.gameid = ' . intval($this->gameid) . '
							AND gs.userid = ' . intval($user->id) . '
							AND gs.gridstatus = ' . intval(GRIDSTATUS_ASSIGNED) . '
							AND g.gridid = gs.gridid
							AND g.gridtype = ' . intval($gridtype);
            $result = $db->query($sql);
            $gridid = ($row = $result->fetch_assoc()) ? intval($row['gridid']) : false;
            while ($gridid === false) {
                // lire les grilles existantes pour ce type de grille
                $sql = 'SELECT *
							FROM gamesstatus gs, grids g
							WHERE gs.gameid = ' . intval($this->gameid) . '
								AND gs.userid = ' . intval($user->id) . '
								AND gs.gridstatus = ' . intval(GRIDSTATUS_ASSIGNED) . '
								AND g.gridid = gs.gridid
								AND g.gridtype = ' . intval($gridtype);
                $result = $db->query($sql);
                $gridid = ($row = $result->fetch_assoc()) ? intval($row['gridid']) : false;
            }
        }
        if ($gridid === false) {
            if ($request == 0) {
                $sql = 'UPDATE gamesusers
							SET request = 1
							WHERE gameid = ' . intval($this->gameid);
                $db->query($sql);
//.........这里部分代码省略.........
开发者ID:ryu38000,项目名称:Magic-Word-game,代码行数:101,代码来源:game.launch.battle.full.class.php

示例5: process

    public function process()
    {
        $user = user::getInstance();
        $db = db::getInstance();
        include './models/game.class.php';
        /*// fermer toute grille en cours pour cet utilisateur
        		$sql = 'UPDATE gamesstatus
        					SET gridstatus = ' . intval(GRIDSTATUS_FINISHED) . '
        					WHERE userid = ' . intval($user->id) . '
        						AND gridstatus = ' . intval(GRIDSTATUS_STARTED);
        		$db->query($sql);*/
        // lire l'invitation
        $invitid = isset($_REQUEST['invitid']) ? intval($_REQUEST['invitid']) : 0;
        $gameid = isset($_REQUEST['gameid']) ? intval($_REQUEST['gameid']) : 0;
        // lire sur invitid
        if ($invitid) {
            $sql = 'SELECT *
						FROM invitations
						WHERE invitid = ' . intval($invitid);
            $result = $db->query($sql);
            $data = ($row = $result->fetch_assoc()) ? $row : false;
            if ($data === false) {
                trigger_error('No invitation', E_USER_ERROR);
            }
            // invitation reçue
            if (intval($data['touserid']) === $user->id) {
                $gametype = GAMETYPE_BATTLE;
                $userids = array($user->id, intval($row['fromuserid']));
                $game = new game();
                $this->gameid = $game->create($userids, $gametype, $user->get_lang());
                $sql = 'UPDATE invitations
							SET gameid = ' . $this->gameid . '
							WHERE invitid = ' . intval($invitid);
                $db->query($sql);
            } else {
                $this->gameid = $row['gameid'];
                $sql = 'DELETE FROM invitations
							WHERE invitid = ' . intval($invitid);
                $db->query($sql);
            }
        } else {
            $this->gameid = intval($gameid);
            $game = new game();
            if (!$game->read($this->gameid)) {
                trigger_error('No game!', E_USER_ERROR);
            }
        }
        // lire les grilles terminées pour trouver le prochain type de grille
        $grid_counts = array();
        $last_grid = 0;
        $sql = 'SELECT userid, COUNT(gridid) AS count_gridid
					FROM gamesstatus
					WHERE gameid = ' . intval($this->gameid) . '
						AND gridstatus = ' . intval(GRIDSTATUS_FINISHED) . '
					GROUP BY userid';
        $result = $db->query($sql);
        while ($row = $result->fetch_assoc()) {
            $grid_counts[intval($row['userid'])] = intval($row['count_gridid']);
            if (intval($row['count_gridid']) > $last_grid && intval($row['userid']) != $user->id) {
                $last_grid = intval($row['count_gridid']);
            }
        }
        if (isset($grid_counts[$user->id])) {
            if ($grid_counts && $last_grid < intval($grid_counts[$user->id])) {
                redirect('game.result&gameid=' . intval($this->gameid));
                exit;
                trigger_error('Wait for the other!', E_USER_ERROR);
            }
        }
        return $this->display();
    }
开发者ID:ryu38000,项目名称:Magic-Word-game,代码行数:71,代码来源:game.launch.battle.main.class.php


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