當前位置: 首頁>>代碼示例>>PHP>>正文


PHP game::start_grid方法代碼示例

本文整理匯總了PHP中game::start_grid方法的典型用法代碼示例。如果您正苦於以下問題:PHP game::start_grid方法的具體用法?PHP game::start_grid怎麽用?PHP game::start_grid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在game的用法示例。


在下文中一共展示了game::start_grid方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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';
        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

示例3: process


//.........這裏部分代碼省略.........
        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);
                // 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);
            }
        } else {
            $grid = new grid();
            $grid->read($gridid, $game->gamelang, $gridtype);
            $game->start_grid($gridid);
            $sql = 'UPDATE gamesusers
						SET request = 0
						WHERE gameid = ' . intval($this->gameid);
            $db->query($sql);
        }
        $res = $grid->get();
        $res->gameid = $this->gameid;
        $res->gametype = GAMETYPE_BATTLE;
        header('Content-Type: application/json');
        echo json_encode($res);
        die;
    }
開發者ID:ryu38000,項目名稱:Magic-Word-game,代碼行數:101,代碼來源:game.launch.battle.full.class.php


注:本文中的game::start_grid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。