Пример #1
0
        public FightRoom Create(List <int> uidList)
        {
            FightRoom room = null;

            //先检测有没有可重用的房间
            if (roomQueue.Count > 0)
            {
                room = roomQueue.Dequeue();
                room.Init(uidList);
            }

            else //没有就直接创建
            {
                room = new FightRoom(id.Add_Get(), uidList);
            }


            //绑定映射关系
            foreach (int uid in uidList)
            {
                uidRoomIDict.Add(uid, room.Id);
                uidFightingList.Add(uid);
            }

            idRoomDict.Add(room.Id, room);
            return(room);
        }
Пример #2
0
        /// <summary>
        /// 创建战斗房间
        /// </summary>
        /// <param name="uidList"></param>
        /// <returns></returns>
        public FightRoom Create(List <int> uidList)
        {
            FightRoom room = null;

            //先检测是否有可以重用的房间
            if (roomQueue.Count > 0)
            {
                room = roomQueue.Dequeue();
                room.Init(uidList);
            }

            else
            {
                room = new FightRoom(id.Add_Get(), uidList);
            }

            //绑定映射关系
            foreach (int uid in uidList)
            {
                uidRoomIDict.Add(uid, room.Id);
                ClientPeer client = userCache.GetClientPeer(uid);
                room.StartFight(uid, client);
            }
            idRoomDict.Add(room.Id, room);
            return(room);
        }
Пример #3
0
        /// <summary>
        /// 创建房间
        /// </summary>
        /// <param name="clientList"></param>
        /// <returns></returns>
        public FightRoom CreatRoom(List <ClientPeer> clientList)
        {
            FightRoom room = null;

            if (roomQueue.Count > 0)
            {
                room = roomQueue.Dequeue();
                room.Init(clientList);
            }
            else
            {
                room = new FightRoom(roomId.Add_Get(), clientList);
            }
            foreach (var client in clientList)
            {
                userIdRoomIdDic.Add(client.Id, room.roomId);
            }
            roomIdModelDic.Add(room.roomId, room);
            return(room);
        }
Пример #4
0
        private ThreadSafeInt roomId = new ThreadSafeInt(-1); // 因为 value++,-1+1=0

        /// <summary>
        /// 创建房间
        /// </summary>
        public FightRoom CreateRoom(List <ClientPeer> clientList)
        {
            FightRoom room = null;

            // 优先从重用队列里取
            if (roomQueue.Count > 0)
            {
                room = roomQueue.Dequeue();
                room.Init(clientList);
            }
            // 如果没有就自己开一间
            else
            {
                room = new FightRoom(roomId.AddGet(), clientList); // 线程安全的整形
            }
            foreach (var client in clientList)
            {
                userIdRoomIdDic.Add(client.Id, room.roomId);
            }
            roomIdModelDic.Add(room.roomId, room);
            return(room);
        }
Пример #5
0
        /// <summary>
        /// 创建房间
        /// </summary>
        /// <returns></returns>
        public FightRoom CreatRoom(List <int> uidList)
        {
            FightRoom room = null;

            //检测是否有重用房间
            if (roomQueue.Count > 0)
            {
                room = roomQueue.Dequeue();
                room.Init(uidList);
            }
            else
            {
                room = new FightRoom(id.Add_Get(), uidList);
            }
            //绑定映射关系
            foreach (int uid in uidList)
            {
                uidRoomIdDict.Add(uid, room.id);
            }
            idRoomDict.Add(room.id, room);
            return(room);
        }