Ejemplo n.º 1
0
        /// <summary>
        /// 退出房间
        /// </summary>
        void ExitRoom()
        {
            RoomMsg  roomMsg  = DataDo.Json2Object <RoomMsg>(Decode.DecodeSecondContendBtyes(bytes));
            RoomInfo roomInfo = GameCommand.GetRoom(roomMsg.roomNum);

            if (roomInfo != null)
            {
                PersonalInfo.ChangeStatusInfo(roomMsg.otherId, "", (int)PersonStatus.OnLine);

                PersonalInfo people = roomInfo.member.Find(it =>
                {
                    if (it.id == roomMsg.otherId)//找到要删的人
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
                roomInfo.RemoveMember(people.id);
                //if (roomMsg.otherId == roomInfo.host_Id && roomInfo.member.Count>0)//退出者的ID为房主
                //{
                //    roomInfo.host_Id = roomInfo.member[0].id;//房主转移
                //}
                Console.WriteLine("剩余人数:" + roomInfo.member.Count);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加入房间(及时响应)
        /// </summary>
        void JoinRoom()
        {
            RoomMsg  roomMsg  = DataDo.Json2Object <RoomMsg>(Decode.DecodeSecondContendBtyes(bytes));
            RoomInfo roomInfo = GameCommand.GetRoom(roomMsg.roomNum);

            if (roomInfo != null)
            {
                PersonalInfo.ChangeStatusInfo(roomMsg.my.id, roomInfo.roomID, (int)PersonStatus.Combine);
                roomMsg.my.IsInWaitRoom = true;
                roomInfo.AddMember(roomMsg.my);
                if (roomInfo.member.Count == RoomInfo.MaxSIZE)//房间人满
                {
                    freeRooms.Remove(roomInfo.roomID);
                }
                ForeachSendRoom((int)SecondCommands.JOINROOM, roomInfo);
                Console.WriteLine("加入成功");
            }
        }