public CityGameController(IHttpContextAccessor httpContextAccessor_, IPlayerService playerService) : base(httpContextAccessor_, playerService)
        {
            string gameCityId_;
            string roomId_;

            if (session.Keys.Contains("RoomId") && session.Keys.Contains("CityId"))
            {
                gameCityId_ = session.GetString("CityId");
                roomId_     = session.GetString("RoomId");
            }
            else
            {
                gameCityId_ = httpContextAccessor.HttpContext.Request.Query["gameCityId"];
                roomId_     = httpContextAccessor.HttpContext.Request.Query["roomId"];
            }


            if (gameCityId_ != null && gameCityId_.Length > 0)
            {
                _gameCity = CityGameController.GameCityList.FindGameCityById(gameCityId_);
            }
            if (roomId_ != null && roomId_.Length > 0)
            {
                _room = _gameCity.FindRoomById(roomId_);
                if (_room == null)
                {
                    throw new RoomIsNotExistException(player.Id, "房间已经不存在了");
                }
                _inngeGame   = _room.InningGame;
                _gameProject = _inngeGame.IGameProject;
            }
        }
Exemple #2
0
        /// <summary>
        /// 玩家离开房间后事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void _room_RemovePlayer_SuccessEvent(object sender, EventArgs e)
        {
            IRoom room = (IRoom)sender;

            if (room.Players.Count == 0)
            {
                IGameCity gameCity = GameCityList.FindGameCityById(room.GameCityId);
                gameCity.RemoveRoom(room);
            }
        }
        public IActionResult ConfigGameCity(string gameCityId)
        {
            IGameCity gameCity = CityGameController.GameCityList.FindGameCityById(gameCityId);

            if (player.Id == gameCity.ICityManager.Id)
            {
                return(View("ConfigGameCity", gameCity));
            }
            return(View("ConfigGameCity", gameCity));
        }
        public IActionResult ConfigGameCity(ConfigGameCityView configGameCity)
        {
            string    id_       = configGameCity.Id;
            IGameCity gameCity_ = CityGameController.GameCityList.FindGameCityById(id_);

            gameCity_.Name        = configGameCity.Name;
            gameCity_.SecretKey   = configGameCity.SecretKey;
            gameCity_.TicketPrice = configGameCity.TicketPrice;
            gameCity_.IsOpening   = configGameCity.IsOpening;
            return(RedirectToAction("Index"));
        }
Exemple #5
0
        /// <summary>
        /// 检查玩家session保存的房间Id等,初始化房间信息
        /// </summary>
        private void LoadRoomInfo()
        {
            string gameCityId_;
            string roomId_;

            #region session中保存有房间信息就读取,没有就从Request.Query中读取
            if (session.Keys.Contains("RoomId") && session.Keys.Contains("CityId"))
            {
                gameCityId_ = session.GetString("CityId");
                roomId_     = session.GetString("RoomId");
            }
            else
            {
                gameCityId_ = httpContextAccessor.HttpContext.Request.Query["gameCityId"];
                roomId_     = httpContextAccessor.HttpContext.Request.Query["roomId"];
            }
            #endregion
            #region sesson或Request.Query中有房间信息就使用
            if (gameCityId_ != null && gameCityId_.Length > 0)
            {
                _gameCity = CityGameController.GameCityList.FindGameCityById(gameCityId_);
            }
            if (roomId_ != null && roomId_.Length > 0)
            {
                _room = _gameCity.FindRoomById(roomId_);
                if (_room == null)
                {
                    throw new RoomIsNotExistException(player.Id, "房间已经不存在了");
                }
                _inngeGame   = _room.InningGame;
                _gameProject = _inngeGame.IGameProject;
                #endregion
                #region 保存玩家websocket对象
                IPlayerJoinRoom roomPlayer = _room.Players.FirstOrDefault(p => p.Id == player.Id);
                if (null != roomPlayer)
                {
                    roomPlayer.WebSocketLink = ClientWebsocketsManager.FindClientWebSocketByPlayerId(player.Id);
                }
                #endregion
            }
        }