Ejemplo n.º 1
0
 public FspRoom(int id)
 {
     m_id = id;
     Console.WriteLine("创建房间:" + id);
     m_state = FspGameState.Create;
 }
Ejemplo n.º 2
0
        private void HandleState()
        {
            switch (m_state)
            {
            case FspGameState.None:
                // 清空所有数据
                break;

            case FspGameState.Create:
                m_state = FspGameState.SelectRole;
                break;

            case FspGameState.SelectRole:
                // 时间到,或者都准备了,开始下一个状态
                foreach (Player item in m_listPlayer)
                {
                    if (!item.tempData.bReady)
                    {
                        return;
                    }
                }
                // 组合要发送的玩家信息
                int[] sendData = new int[m_listPlayer.Count];
                for (int i = 0; i < m_listPlayer.Count; i++)
                {
                    sendData[i] = (int)m_listPlayer[i].id;
                }
                // 通知客户端开始加载游戏
                foreach (Player item in m_listPlayer)
                {
                    FspMsgPlayerData msg = (FspMsgPlayerData)NetManager.Inst.GetMessage(eNetMessageID.FspMsgPlayerData);
                    msg.m_sendData = sendData;
                    FspNetRunTime.Inst.Send(item.conn, msg);
                }
                m_state = FspGameState.StartLoad;
                break;

            case FspGameState.StartLoad:
                if (m_listPlayer.Count == 0)
                {
                    return;
                }
                // 临时组合要发送的玩家进度
                float[] progress = new float[m_listPlayer.Count];
                for (int i = 0; i < m_listPlayer.Count; i++)
                {
                    progress[i] = (int)m_listPlayer[i].tempData.m_loadProgress;
                }
                foreach (Player item in m_listPlayer)
                {
                    FspMsgLoadProgress msg = (FspMsgLoadProgress)NetManager.Inst.GetMessage(eNetMessageID.FspMsgLoadProgress);
                    msg.m_sendProgress = progress;
                    FspNetRunTime.Inst.Send(item.conn, msg);
                }
                foreach (Player item in m_listPlayer)
                {
                    if (!item.tempData.bLoaded)
                    {
                        return;
                    }
                }
                Console.WriteLine("接受玩家全部加载完成 发送开始控制");
                // 如果都加载完成,就发送开始控制,正式时可附带信息
                foreach (Player item in m_listPlayer)
                {
                    FspMsgStartControl msg = (FspMsgStartControl)NetManager.Inst.GetMessage(eNetMessageID.FspMsgStartControl);
                    FspNetRunTime.Inst.Send(item.conn, msg);
                }
                m_state = FspGameState.StartControl;
                break;

            case FspGameState.StartControl:

                break;
            }
        }