示例#1
0
        public static void updateRoomInfo(int roomID, int PlayerColor, int state)
        {
            RedisValue roomInfoValue = db.HashGet(new RedisKey("room"), new RedisValue(roomID.ToString()));
            RoomInfo   roomInfo      = (RoomInfo)JsonConvert.DeserializeObject(roomInfoValue.ToString(), typeof(RoomInfo));

            //玩家加入房间
            if (state == 0)
            {
                switch (PlayerColor)
                {
                case 1:
                    roomInfo.BlackPlayerNum++;
                    roomInfo.TotalNum++;
                    break;

                case 2:
                    roomInfo.WhitePlayerNum++;
                    roomInfo.TotalNum++;
                    break;

                case 3:
                    roomInfo.AudienceNum++;
                    roomInfo.TotalNum++;
                    break;

                default:
                    break;
                }
                addRoomInfo(roomInfo);
                //玩家离开房间
            }
            else if (state == 1)
            {
                //仅剩一个人,离开后删除房间
                if (roomInfo.TotalNum == 1)
                {
                    db.HashDelete(new RedisKey("room"), new RedisValue(roomID.ToString()));
                }
                else
                {
                    switch (PlayerColor)
                    {
                    case 1:
                        roomInfo.BlackPlayerNum--;
                        roomInfo.TotalNum--;
                        break;

                    case 2:
                        roomInfo.WhitePlayerNum--;
                        roomInfo.TotalNum--;
                        break;

                    case 3:
                        roomInfo.AudienceNum--;
                        roomInfo.TotalNum--;
                        break;

                    default:
                        break;
                    }
                    addRoomInfo(roomInfo);
                }
            }
        }
示例#2
0
        public static void addRoomInfo(RoomInfo roomInfo)
        {
            string roomInfoStr = JsonConvert.SerializeObject(roomInfo);

            db.HashSet(new RedisKey("room"), new RedisValue(roomInfo.RoomID.ToString()), new RedisValue(roomInfoStr));
        }