/// <summary> /// 根据用户id获取所在的房间 /// </summary> /// <param name="uid"></param> /// <returns></returns> public SingleRoom GetRoomByUId(int uid) { if (uidRoomIDict.ContainsKey(uid) == false) { throw new Exception("当前用户不在房间"); } int roomId = uidRoomIDict[uid]; SingleRoom room = GetRoom(roomId); return(room); }
/// <summary> /// 获取房间 /// </summary> /// <param name="id"></param> /// <returns></returns> public SingleRoom GetRoom(int id) { if (idRoomDict.ContainsKey(id) == false) { // return null; throw new Exception("不存在这个房间"); } SingleRoom room = idRoomDict[id]; return(room); }
/// <summary> /// 摧毁房间 /// </summary> /// <param name="room"></param> public void Destroy(SingleRoom room) { //移除映射关系 idRoomDict.Remove(room.Id); uidRoomIDict.Remove(room.player.UserId); //初始化房间数据 room.player = null; room.DealerCardList.Clear(); room.libraryModel.Init(); room.Multiple = 1; room.Wager = 10; //添加到重用队列里面等待重用 roomQueue.Enqueue(room); }
/// <summary> /// 创建战斗房间 /// </summary> /// <returns></returns> public SingleRoom Create(int uid) { SingleRoom room = null; //先检测有没有可重用的房间 if (roomQueue.Count > 0) { room = roomQueue.Dequeue(); //fixbug923 room.Init(uid); } else//没有就直接创建 { room = new SingleRoom(id.Add_Get(), uid); } //绑定映射关系 uidRoomIDict.Add(uid, room.Id); idRoomDict.Add(room.Id, room); return(room); }