示例#1
0
 /**
  * 构建
  * BaseController constructor.
  */
 public function __construct()
 {
     // 认证
     $objUser = Auth::user();
     $intPlayerId = $objUser->id;
     $this->_intPlayerId = $intPlayerId;
     $this->_strDeviceId = $intPlayerId;
     echo "====================================<br />";
     echo "[TOP INFO]PlayerId:" . $this->_intPlayerId . "DeviceId:" . $this->_strDeviceId . "<br />";
     echo "[TOP 菜单] ";
     echo "<a href='/game?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>测试TOP</a> ";
     echo "<a href='/game/player?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>玩家情报TOP</a> ";
     echo "<a href='/game/player/team?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>玩家队伍编辑</a> ";
     echo "<a href='/game/player/card-box?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>玩家卡片Box</a> ";
     echo "<a href='/game/player/equipment-box?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>玩家装备Box</a>";
     echo "<br />";
     echo "====================================<br />";
     // 初始化玩家数据
     $objPlayer = Player::find($this->_intPlayerId);
     $objPlayerData = PlayerData::find($objPlayer->id);
     $this->_lstPlayer = array_merge($objPlayerData->toArray(), $objPlayer->toArray());
     echo "[TOP 玩家状态] <br />";
     echo "Lv." . $this->_lstPlayer["level"] . " 体力:" . $this->_lstPlayer["stamina"] . "/" . $this->_lstPlayer["max_stamina"];
     echo " 魔法石:" . $this->_lstPlayer["stone"];
     echo " 金币:" . $this->_lstPlayer["money"];
     echo "<br />";
     echo "====================================<br />";
 }
示例#2
0
 public function __construct()
 {
     // Always run csrf protection before the request when posting
     $playerId = Input::get('player_id');
     $player = Player::find($playerId);
     $this->_player = $player;
     $this->_playerData = PlayerData::find($player->id);
 }
示例#3
0
 public function __construct()
 {
     // Always run csrf protection before the request when posting
     $this->beforeFilter(function () {
         $deviceId = Input::get('device_id');
         $playerId = Input::get('player_id');
         $player = Player::find($playerId);
         if (!$player || $player->device_id != $deviceId) {
             return 'Login Error';
         }
         $this->_player = $player;
         $this->_playerData = PlayerData::find($player->id);
     });
     // Here's something that happens after the request
     $this->afterFilter(function () {
         // something
     });
 }
示例#4
0
 /**
  * 创建玩家实例
  */
 public function create()
 {
     // 取得玩家终端ID
     $intDeviceId = Input::get('device_id');
     // 终端ID检查
     if (!$intDeviceId || $intDeviceId == "") {
         return 'Create Error';
     }
     // 检查玩家是否已经存在
     $objPlayerCheck = Player::where('device_id', $intDeviceId)->get();
     if (!empty($objPlayerCheck->toArray())) {
         return 'Player Is Exsit';
     }
     // TODO Truncate
     DB::beginTransaction();
     // 创建玩家实例
     $objPlayer = new Player();
     $objPlayer->device_id = $intDeviceId;
     if ($objPlayer->save()) {
         // 若玩家实例创建成功,创建玩家数据
         $objPlayerData = new PlayerData();
         // 玩家数据初始化 TODO
         $objPlayerData->id = $objPlayer->id;
         $objPlayerData->code = "";
         $objPlayerData->profile = "";
         $objPlayerData->money = 500;
         $objPlayerData->stone = 50;
         if ($objPlayerData->save()) {
             // 最初的卡片赋予 TODO 初始卡片选择
             $objPlayer->appendCard(1);
             // 最初的队伍组建
             $objPlayer->firstTeam();
             // 其他初始化项目 如果有的话添加
             DB::commit();
             return Response::json($objPlayerData);
         } else {
             // 若保持失败
             DB::rollback();
             return Response::json(null);
         }
     } else {
         // 若保持失败
         DB::rollback();
         return Response::json(null);
     }
 }