Example #1
0
        public FSPPlayer AddPlayer(uint playerId, FSPSession session)
        {
            if (state != FSPGameState.Create)
            {
                Debuger.LogError("当前状态下无法AddPlayer! State = {0}", state);
                return(null);
            }

            FSPPlayer player = null;

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

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

            player = new FSPPlayer();
            player.Create(playerId, authID, session, OnRecvFromPlayer);
            listPlayer.Add(player);

            return(player);
        }
Example #2
0
        private bool CheckGameAbnormalEnd()
        {
            if (listPlayer.Count < 1)
            {
                SetGameState(FSPGameState.GameEnd, (int)FSPGameEndReason.AllOtherExit);
                AddBasicCmdToCurrentFrame(FSPProtoCmd.GameEnd, (int)FSPGameEndReason.AllOtherExit);
                return(true);
            }

            for (int i = 0; i < listPlayer.Count; i++)
            {
                FSPPlayer player = listPlayer[i];
                if (player.IsLose())
                {
                    listPlayer.RemoveAt(i);
                    player.Release();
                    --i;
                }
            }

            if (listPlayer.Count < 1)
            {
                SetGameState(FSPGameState.GameEnd, (int)FSPGameEndReason.AllOtherLost);
                AddBasicCmdToCurrentFrame(FSPProtoCmd.GameEnd, (int)FSPGameEndReason.AllOtherLost);
                return(true);
            }
            return(false);
        }