Пример #1
0
        //============================================================

        /// <summary>
        /// 检测游戏是否异常结束
        /// </summary>
        private bool CheckGameAbnormalEnd()
        {
            //判断还剩下多少玩家,如果玩家少于2,则表示至少有玩家主动退出
            if (m_ListPlayer.Count < 1)
            {
                //直接进入GameEnd状态
                SetGameState(FSPGameState.GameEnd, (int)FSPGameEndReason.AllOtherExit);
                AddBasicCmdToCurrentFrame(FSPBasicCmd.GAME_END, (int)FSPGameEndReason.AllOtherExit);
                return(true);
            }

            // 检测玩家在线状态
            for (int i = 0; i < m_ListPlayer.Count; i++)
            {
                FSPPlayer player = m_ListPlayer[i];
                if (player.IsLose())
                {
                    m_ListPlayer.RemoveAt(i);
                    player.Release();
                    --i;
                }
            }

            //判断还剩下多少玩家,如果玩家少于1,则表示至少有玩家主动退出
            if (m_ListPlayer.Count < 1)
            {
                //直接进入GameEnd状态
                SetGameState(FSPGameState.GameEnd, (int)FSPGameEndReason.AllOtherLost);
                AddBasicCmdToCurrentFrame(FSPBasicCmd.GAME_END, (int)FSPGameEndReason.AllOtherLost);
                return(true);
            }


            return(false);
        }
Пример #2
0
        public void Release()
        {
            SetGameState(FSPGameState.None);

            for (int i = 0; i < m_ListPlayer.Count; i++)
            {
                FSPPlayer player = m_ListPlayer[i];
                player.Release();
            }
            m_ListPlayer.Clear();
            m_ListPlayersExitOnNextFrame.Clear();

            onGameExit = null;
            onGameEnd  = null;

            Debuger.Log();
        }
Пример #3
0
        //===================================================================

        public FSPPlayer AddPlayer(uint playerId, FSPSession session)
        {
            Debuger.Log("playerId:{0}", playerId);

            if (m_State != FSPGameState.Create)
            {
                Debuger.LogError("当前状态下无法AddPlayer! State = {0}", m_State);
                return(null);
            }

            FSPPlayer player = null;

            for (int i = 0; i < m_ListPlayer.Count; i++)
            {
                player = m_ListPlayer[i];
                if (player.id == playerId)
                {
                    Debuger.LogWarning("PlayerId已经存在!用新的替代旧的! PlayerId = " + playerId);
                    m_ListPlayer.RemoveAt(i);
                    player.Release();
                    break;
                }
            }

            if (m_ListPlayer.Count >= MaxPlayerNum)
            {
                Debuger.LogError("已经达到最大玩家数了! MaxPlayerNum = {0}", MaxPlayerNum);
                return(null);
            }


            player = new FSPPlayer();
            player.Create(playerId, m_authId, session, OnRecvFromPlayer);
            m_ListPlayer.Add(player);

            return(player);
        }