コード例 #1
0
    void timerCallback(object obj)
    {
        try
        {
            switch ((TimerType)obj)
            {
            case TimerType.TimerType_waitMatchTimeOut:
            {
                if (m_roomState == DDZ_RoomState.RoomState_waiting)
                {
                    LogUtil.getInstance().writeRoomLog(this, "匹配时间结束,给房间添加机器人");
                    DDZ_GameLogic.doTask_WaitMatchTimeOut(this);
                }
            }
            break;

            case TimerType.TimerType_pvpNextStartGame:
            {
                // 检测房间人数是否可以开赛
                DDZ_GameLogic.checkRoomStartGame(this, m_tag);
            }
            break;

            case TimerType.TimerType_callPlayerOutPoker:
            {
                // 让下一个人出牌
                DDZ_GameLogic.doTask_CallPlayerOutPoker(m_gameBase, this, m_curOutPokerPlayer);
            }
            break;

            case TimerType.TimerType_gameOver:
            {
                m_gameBase.gameOver(this);
            }
            break;
            }
        }
        catch (Exception ex)
        {
            TLJ_PlayService.PlayService.log.Error("RoomData----" + "timerCallback异常: " + ex);
        }
    }
コード例 #2
0
    void doTask_JoinGame(IntPtr connId, string data)
    {
        try
        {
            JObject jo           = JObject.Parse(data);
            string  tag          = jo.GetValue("tag").ToString();
            string  uid          = jo.GetValue("uid").ToString();
            string  gameroomtype = jo.GetValue("gameroomtype").ToString();
            int     playAction   = Convert.ToInt32(jo.GetValue("playAction"));

            DDZ_RoomData room = null;

            // 检测该玩家是否已经加入房间
            if (DDZ_GameUtil.checkPlayerIsInRoom(uid))
            {
                // 给客户端回复
                {
                    JObject respondJO = new JObject();
                    respondJO.Add("tag", tag);
                    respondJO.Add("playAction", playAction);
                    respondJO.Add("gameRoomType", DDZ_GameUtil.getRoomByUid(uid).m_gameRoomType);
                    respondJO.Add("code", (int)TLJCommon.Consts.Code.Code_CommonFail);

                    // 发送给客户端
                    PlayService.m_serverUtil.sendMessage(connId, respondJO.ToString());
                }

                return;
            }

            lock (m_roomList)
            {
                // 在已有的房间寻找可以加入的房间
                for (int i = 0; i < m_roomList.Count; i++)
                {
                    if ((gameroomtype.CompareTo(m_roomList[i].m_gameRoomType) == 0) && (m_roomList[i].getRoomState() == DDZ_RoomState.RoomState_waiting))
                    {
                        if (m_roomList[i].joinPlayer(new DDZ_PlayerData(connId, uid, false, gameroomtype)))
                        {
                            room = m_roomList[i];
                            break;
                        }
                    }
                }

                // 当前没有房间可加入的话则创建一个新的房间
                if (room == null)
                {
                    room = new DDZ_RoomData(this, gameroomtype);
                    room.joinPlayer(new DDZ_PlayerData(connId, uid, false, gameroomtype));

                    m_roomList.Add(room);

                    LogUtil.getInstance().writeRoomLog(room, "新建比赛场房间:" + room.getRoomId());
                }
            }

            // 加入房间成功,给客户端回复
            {
                JObject respondJO = new JObject();
                respondJO.Add("tag", tag);
                respondJO.Add("playAction", playAction);
                respondJO.Add("gameRoomType", gameroomtype);
                respondJO.Add("code", (int)TLJCommon.Consts.Code.Code_OK);
                respondJO.Add("roomId", room.getRoomId());

                // 发送给客户端
                PlayService.m_serverUtil.sendMessage(connId, respondJO.ToString());
            }

            // 检测房间人数是否可以开赛
            DDZ_GameLogic.checkRoomStartGame(room, tag);
        }
        catch (Exception ex)
        {
            TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":doTask_JoinGame异常:" + ex);
        }
    }