Пример #1
0
 public void SetOffLineByState(AsyncUserToken userToken)
 {
     if (userToken.userInfo.RoomID != -1)
     {
         SingleRoom room = allRoom.RoomList[userToken.userInfo.RoomID];
         if (room.CurState != RoomActorState.NoReady)
         {
             Log4Debug("用户账号:" + userToken.userInfo.Register.userID + " 掉线前保存房间号:" + userToken.userInfo.RoomID);
             OffLineRooms.AddOrUpdate(userToken.userInfo.Register.userID, -1, (key, oldValue) => userToken.userInfo.RoomID);
             //更新掉线用户的状态
             RoomActorUpdate roomActorUpdate = new RoomActorUpdate()
             {
                 userIndex = userToken.userInfo.UniqueID,
                 update    = (int)RoomActorState.Offline + ""
             };
             room.ClearUDP(userToken.userInfo.UniqueID);
             room.UpdateState(roomActorUpdate);
         }
         else
         {
             room.Quit(userToken.userInfo.UniqueID);
             Log4Debug("用户:" + userToken.userInfo.Register.userID + " 掉线,房间不保存。房间状态:" + room.CurState);
         }
     }
 }
        public IHttpActionResult PutRoom(int id, SingleRoom room)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != room.Id)
            {
                return(BadRequest());
            }

            db.Entry(room).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 /// <summary>
 /// Add a new room to the list of rooms.
 /// </summary>
 /// <param name="room"></param>
 public void AddRoom(SingleRoom room)
 {
     if (!_rooms.RoomData.Contains(room))
     {
         _rooms.RoomData.Add(room);
     }
 }
 /// <summary>
 /// Deletes an already created room from the list of rooms.
 /// </summary>
 /// <param name="room"></param>
 public void DeleteRoom(SingleRoom room)
 {
     if (_rooms.RoomData.Contains(room))
     {
         _rooms.RoomData.Remove(room);
     }
 }
Пример #5
0
    public byte[] UpdateRoom(JObject json)
    {
        byte[] backData = null;

        string    userID   = (string)json[nameof(Register.userID)];
        int       roomID   = (int)json[nameof(RoomInfo.RoomID)];
        GameModel roomType = (GameModel)(int)json[nameof(RoomInfo.RoomType)];
        string    roomName = (string)json[nameof(RoomInfo.RoomName)];

        //房间存在
        if (RoomList.ContainsKey(roomID))
        {
            SingleRoom singleRoom = null;
            if (RoomList.TryGetValue(roomID, out singleRoom) && singleRoom.IsMaster(userID))//发起者是房主
            {
                singleRoom.UpdateRoom(roomType, roomName);
                RoomInfo info = singleRoom.RoomInfo;
                backData = SerializeHelper.Serialize <RoomInfo>(info);
            }
        }
        else
        {
            backData = ClassGroup.ErrorBackByType(ErrorType.roomNotExist);
        }
        return(backData);
    }
Пример #6
0
 static void Main()
 {
    HotelRoom aRoom = new HotelRoom(234);
    SingleRoom aSingle = new SingleRoom(135); 
    Suite aSuite = new Suite(453);
    Console.WriteLine(aRoom.ToString());
    Console.WriteLine(aSingle.ToString());
    Console.WriteLine(aSuite.ToString();
 }
Пример #7
0
        static void Main(string[] args)
        {
            IFrontDesk frontDesk            = new FrontDesk();
            var        commissionCalculator = new CommissionCalculator();

            Console.WriteLine("Select asset type: \n" +
                              "1. House; \n" +
                              "2. Apartment; \n" +
                              "3. Single Room; \n" +
                              "4. Urban Plot. \n");

            var assetType = Console.ReadLine();

            IAsset asset;

            switch (assetType)
            {
            case "1":
                asset = new House();
                Console.WriteLine("Insert the address of the House: ");
                asset.SetAssetAttribute(Console.ReadLine());
                Console.WriteLine("\nInsert the desired price: ");
                asset.Price = Convert.ToDecimal(Console.ReadLine());
                frontDesk.CalculateSellingPrice(asset, commissionCalculator);
                break;

            case "2":
                asset = new Apartment();
                Console.WriteLine("Insert the address of the Apartment: ");
                asset.SetAssetAttribute(Console.ReadLine());
                Console.WriteLine("\nInsert the desired price: ");
                asset.Price = Convert.ToDecimal(Console.ReadLine());
                frontDesk.CalculateSellingPrice(asset, commissionCalculator);
                break;

            case "3":
                asset = new SingleRoom();
                Console.WriteLine("Insert the address of the Single Room: ");
                asset.SetAssetAttribute(Console.ReadLine());
                Console.WriteLine("\nInsert the desired price: ");
                asset.Price = Convert.ToDecimal(Console.ReadLine());
                frontDesk.CalculateSellingPrice(asset, commissionCalculator);
                break;

            case "4":
                asset = new UrbanPlot();
                Console.WriteLine("Insert the Cadastral Reference of the Urban Plot: ");
                asset.SetAssetAttribute(Console.ReadLine());
                Console.WriteLine("\nInsert the desired price: ");
                asset.Price = Convert.ToDecimal(Console.ReadLine());
                frontDesk.CalculateSellingPrice(asset, commissionCalculator);
                break;

            default:
                break;
            }
        }
Пример #8
0
        /// <summary>
        /// 要牌
        /// </summary>
        /// <param name="client"></param>
        public void getCard(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                //必须确保在线
                int userId = userCache.GetId(client);

                SingleRoom room = singleCache.GetRoomByUId(userId);
                if (room.isPlayer21())
                {
                    client.Send(OpCode._21Single, _21SingleCode.GET_SRES, null);    //已经21点不能要牌,最好客户端设置一下
                    return;
                }
                CardDto dto = room.GetOnePlayerCard();
                client.Send(OpCode._21Single, _21SingleCode.GET_SRES, dto);
                if (room.GetPlayerWeight() > 21)                                           //闲家爆牌 这局结束
                {
                    if (room.player.SplitNum > 1)                                          //是分牌的情况
                    {
                        client.Send(OpCode._21Single, _21SingleCode.SPLIT_PROMST_SRES, 2); //闲家爆牌
                        //room.player.winOrLose.Add(-1);
                        //room.player.SpliteCardListList.Add(room.player.CardList);
                        room.SaveList(1, false);
                        if (room.player.SpliteCardListQueue.Count() > 0)
                        {
                            client.Send(OpCode._21Single, _21SingleCode.SPLIT_CAN_NEXT_SRES, null);
                        }
                        else
                        {
                            gameOver(userId, room, 7);
                        }
                    }
                    else
                    {
                        client.Send(OpCode._21Single, _21SingleCode.NGET_SRES, null);
                        gameOver(userId, room, 2);
                    }
                }
                else if (room.GetPlayerWeight() != 21)
                {
                    BasicStrategyDto basicStrategyDto = new BasicStrategyDto();
                    basicStrategyDto.dealerCardType   = room.getDealerCardType();
                    basicStrategyDto.playerCardType   = room.getPlayerCardType();
                    basicStrategyDto.realAns          = basicStrategy.trueStrategy(basicStrategyDto.dealerCardType, basicStrategyDto.playerCardType);
                    client.Send(OpCode._21Single, _21SingleCode.BASIC_STRATEGY_SRES, basicStrategyDto);
                }
                else
                {
                    client.Send(OpCode._21Single, _21SingleCode.BASIC_STRATEGY_SRES, null);
                }
            });
        }
Пример #9
0
        /// <summary>
        /// 下一把
        /// </summary>
        /// <param name="client"></param>
        public void nextGame(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                //必须确保在线
                int userId = userCache.GetId(client);

                SingleRoom room = singleCache.GetRoomByUId(userId);
                room.Multiple   = 1;
                if (room.libraryModel.CardQueue.Count() < 12)
                {
                    room.libraryModel.Init();
                    client.Send(OpCode._21Single, _21SingleCode.RESHUFF_SRES, null);    //重新洗牌,给客户端,让客户端给提示
                }
                //测试,只发俩A
                //room.TestInitPlayerCards();
                room.InitPlayerCards();
                //发送给客户端 他自身有什么牌 庄家有什么牌
                List <CardDto> cardList = room.GetUserCards(userId);
                client.Send(OpCode._21Single, _21SingleCode.GET_PCARD_SRES, cardList);
                client.Send(OpCode._21Single, _21SingleCode.GET_DCARD_SRES, room.DealerCardList);
                Thread.Sleep(100);
                //摸到21点,牛逼,游戏结束
                if (room.isPlayer21())    //21点 这局结束
                {
                    //client.Send(OpCode._21Single, _21SingleCode.OVER_SRES, 1);
                    client.Send(OpCode._21Single, _21SingleCode.NGET_SRES, null);
                    gameOver(userId, room, 1);
                }
                //能够分牌了
                else if (cardList.Count > 1 && cardList[0].Weight == cardList[1].Weight)
                {
                    BasicStrategyDto basicStrategyDto = new BasicStrategyDto();
                    basicStrategyDto.dealerCardType   = room.getDealerCardType();
                    basicStrategyDto.playerCardType   = room.getPlayerCardType();
                    basicStrategyDto.realAns          = basicStrategy.trueStrategy(basicStrategyDto.dealerCardType, basicStrategyDto.playerCardType);
                    client.Send(OpCode._21Single, _21SingleCode.BASIC_STRATEGY_SRES, basicStrategyDto);
                    client.Send(OpCode._21Single, _21SingleCode.CAN_SPLIT_SRES, null);
                }
                else
                {
                    BasicStrategyDto basicStrategyDto = new BasicStrategyDto();
                    basicStrategyDto.dealerCardType   = room.getDealerCardType();
                    basicStrategyDto.playerCardType   = room.getPlayerCardType();
                    basicStrategyDto.realAns          = basicStrategy.trueStrategy(basicStrategyDto.dealerCardType, basicStrategyDto.playerCardType);
                    client.Send(OpCode._21Single, _21SingleCode.BASIC_STRATEGY_SRES, basicStrategyDto);
                }
            });
        }
Пример #10
0
    public static void TenFour()
    {
        HotelRoom  aRoom   = new HotelRoom(234);
        SingleRoom aSingle = new SingleRoom(135);
        Suite      aSuite  = new Suite(453);

        WriteLine(aRoom.ToString());
        WriteLine(aSingle.ToString());
        WriteLine(aSuite.ToString());//add )
        System.Console.ReadLine();
    }
    public void MoveRoom()
    {
        //移动场景中的房间

        //改变房间在数组中的位置
        SingleRoom tmp = rooms[1][1];

        rooms[1][1] = rooms[3][1];
        rooms[3][1] = rooms[3][3];
        rooms[3][3] = rooms[1][3];
        rooms[1][3] = tmp;
    }
 // Start is called before the first frame update
 void Start()
 {
     itemSetCount = 0;
     //初始化所有的房间变量
     for (int i = 0; i < 5; i++)
     {
         for (int j = 0; j < 5; j++)
         {
             rooms[i][j] = new SingleRoom();
         }
     }
 }
Пример #13
0
        public void DeleteRoom(string SelectedRoom)
        {
            var AllRooms = RoomRepo.LoadRooms();

            foreach (var SingleRoom in AllRooms)
            {
                if (SingleRoom.RetrieveRoomName() == SelectedRoom)
                {
                    RoomRepo.DeleteRoom(SelectedRoom);
                }
            }
        }
Пример #14
0
    public SingleRoom GetSingleRoomByID(int roomID)
    {
        SingleRoom room = null;

        lock (allRoom.RoomList)
        {
            if (allRoom.RoomList.ContainsKey(roomID))
            {
                room = allRoom.RoomList[roomID];
            }
        }
        return(room);
    }
Пример #15
0
    public RoomCollection()
    {
        RoomList = new ConcurrentDictionary <int, SingleRoom>();
        SingleRoom singleRoom = new SingleRoom(0, "", GameModel.组队模式);

        RoomList.AddOrUpdate(0, singleRoom, (key, oldValue) => singleRoom);
        //// 建立聊天室的名字以及容許人數
        //roomList.Add(new SingleRoom("公開聊天室1", 20));
        //roomList.Add(new SingleRoom("公開聊天室2", 20));
        //roomList.Add(new SingleRoom("公開聊天室3", 20));
        //roomList.Add(new SingleRoom("公開聊天室4", 20));
        //roomList.Add(new SingleRoom("公開聊天室5", 20));
    }
Пример #16
0
        public void splitNextCard(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                //必须确保在线
                int userId = userCache.GetId(client);

                SingleRoom room = singleCache.GetRoomByUId(userId);
                room.NextHandCard();
                List <CardDto> cardList = room.GetUserCards(userId);
                client.Send(OpCode._21Single, _21SingleCode.GET_PCARD_SRES, cardList);

                if (room.isPlayer21())    //21点 这局结束
                {
                    room.SaveList(1, false);
                    //room.player.SpliteCardListList.Add(cardList);
                    if (room.player.SpliteCardListQueue.Count() > 0)
                    {
                        client.Send(OpCode._21Single, _21SingleCode.SPLIT_PROMST_SRES, 1);    //21点牛逼
                        //room.player.winOrLose.Add(1.5);
                        client.Send(OpCode._21Single, _21SingleCode.SPLIT_CAN_NEXT_SRES, null);
                    }
                    else
                    {
                        gameOver(userId, room, 7);
                    }
                }
                else if (cardList.Count > 1 && cardList[0].Weight == cardList[1].Weight)
                {
                    BasicStrategyDto basicStrategyDto = new BasicStrategyDto();
                    basicStrategyDto.dealerCardType   = room.getDealerCardType();
                    basicStrategyDto.playerCardType   = room.getPlayerCardType();
                    basicStrategyDto.realAns          = basicStrategy.trueStrategy(basicStrategyDto.dealerCardType, basicStrategyDto.playerCardType);
                    client.Send(OpCode._21Single, _21SingleCode.BASIC_STRATEGY_SRES, basicStrategyDto);
                    client.Send(OpCode._21Single, _21SingleCode.CAN_SPLIT_SRES, null);
                }
                else
                {
                    BasicStrategyDto basicStrategyDto = new BasicStrategyDto();
                    basicStrategyDto.dealerCardType   = room.getDealerCardType();
                    basicStrategyDto.playerCardType   = room.getPlayerCardType();
                    basicStrategyDto.realAns          = basicStrategy.trueStrategy(basicStrategyDto.dealerCardType, basicStrategyDto.playerCardType);
                    client.Send(OpCode._21Single, _21SingleCode.BASIC_STRATEGY_SRES, basicStrategyDto);
                }
            });
        }
Пример #17
0
 /// <summary>
 /// 设置赌注
 /// </summary>
 /// <param name="client"></param>
 public void setWager(ClientPeer client, int wager)
 {
     SingleExecute.Instance.Execute(
         delegate()
     {
         if (userCache.IsOnline(client) == false)
         {
             return;
         }
         //必须确保在线
         int userId = userCache.GetId(client);
         //创建战斗房间
         SingleRoom room = singleCache.GetRoomByUId(userId);
         room.Wager      = wager;
     });
 }
Пример #18
0
        /// <summary>
        /// 不要牌
        /// </summary>
        /// <param name="client"></param>
        public void ngetCard(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                //必须确保在线
                int userId = userCache.GetId(client);

                SingleRoom room = singleCache.GetRoomByUId(userId);

                //client.Send(OpCode._21Single, _21SingleCode.OVER_SRES, whichwin);
                //说明是分牌的
                if (room.player.SplitNum > 1)
                {
                    //room.addWeightAndMulti(1);
                    room.SaveList(3, false);
                    //client.Send(OpCode._21Single, _21SingleCode.SPLIT_PROMST_SRES, whichwin);
                    //先不能判断输赢
                    if (room.player.SpliteCardListQueue.Count() > 0)
                    {
                        client.Send(OpCode._21Single, _21SingleCode.SPLIT_PROMST_SRES, 0);    //随便提示一下

                        client.Send(OpCode._21Single, _21SingleCode.SPLIT_CAN_NEXT_SRES, null);
                    }
                    else
                    {
                        gameOver(userId, room, 7);
                    }
                }
                else
                {
                    client.Send(OpCode._21Single, _21SingleCode.NGET_SRES, null);
                    while (room.GetDealerWeight() < 17)
                    {
                        CardDto dto = room.GetOneDealerCard();
                        client.Send(OpCode._21Single, _21SingleCode.ADD_DCARD_SRES, dto);
                    }

                    int whichwin = room.whichWin();
                    gameOver(userId, room, whichwin);
                }
            });
        }
Пример #19
0
 /// <summary>
 /// 匹配,创建一个房间
 /// </summary>
 /// <param name="client"></param>
 public void matchCard(ClientPeer client)
 {
     SingleExecute.Instance.Execute(
         delegate()
     {
         if (userCache.IsOnline(client) == false)
         {
             return;
         }
         //必须确保在线
         int userId = userCache.GetId(client);
         //创建战斗房间
         SingleRoom room = singleCache.Create(userId);
         //CountStrategyDto countStrategyDto = room.libraryModel.GetCountStrategyDto();
         //client.Send(OpCode._21Single, _21SingleCode.COUNT_STRATEGY_SRES, countStrategyDto);
     });
 }
Пример #20
0
        /// <summary>
        /// 用户离开
        /// </summary>
        /// <param name="client"></param>
        private void leave(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                () =>
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }

                //必须确保在线
                int userId = userCache.GetId(client);
                if (singleCache.IsFighting(userId) == false)
                {
                    return;
                }

                SingleRoom room = singleCache.GetRoomByUId(userId);
                //销毁缓存层的房间数据
                singleCache.Destroy(room);
            });
        }
Пример #21
0
        private static void Main(string[] args)
        {
            List <ABed>             _beds           = new(){ new Standard(1, false, 100f), new Standard(1, false, 100f) };
            TV                      tv              = new TV(TV.channelsAvailable.local, true, 0.2f, "Samsung 14000xY Ultimate Local Smart TV", 100f, 0.4f, 0.1f);
            Fridge                  fridge          = new Fridge(0.0f, "Fridge x3400", 30f, 0.02f, 0.0f);
            HashSet <ARoomProperty> aRoomProperties = new HashSet <ARoomProperty>()
            {
                tv, fridge
            };
            SingleRoom single1 = new SingleRoom(aRoomProperties, _beds);

            SingleRoom single2 = new(){ Beds = _beds, RoomProperties = aRoomProperties };

            ARoom[]    rooms = { single1, single2 };
            HotelFloor hf    = new HotelFloor(rooms);
            Dictionary <int, HotelFloor> floors = new();

            floors.Add(1, hf);
            ICustomer customer = new Customer
            {
                Age            = 43,
                Firstname      = "Freddy",
                Lastname       = "Dos Santos",
                PhoneNumber    = 92340234,
                RoomPreference = new RoomPreference
                {
                    Beds  = _beds,
                    Price = 33f
                }
            };
            ReservationManager rm = new ReservationManager();
            HotelManager       hm = new HotelManager(floors, rm);

            Console.WriteLine("hello world!");
            Console.ReadKey();
        }
    }
}
Пример #22
0
    public byte[] SelectMessage(byte[] data, EndPoint endPoint)
    {
        string strPoint = endPoint.ToString();

        byte[]       newBuffer = null;
        MessageXieYi xieyi     = MessageXieYi.FromBytes(data);

        if (xieyi == null)
        {
            return(newBuffer);
        }

        byte[]             tempMessageContent = xieyi.MessageContent;
        ActorMoveDirection moveDirection      = null;
        SingleRoom         room  = null;
        UDPLogin           login = null;

        //该处RoomList没有加锁
        if (ServerDataManager.instance.allRoom.RoomList.ContainsKey(allUDPs[strPoint].roomID))
        {
            room = ServerDataManager.instance.allRoom.RoomList[allUDPs[strPoint].roomID];
        }

        switch ((MessageConvention)xieyi.XieYiFirstFlag)
        {
        case MessageConvention.setUDP:
            login       = SerializeHelper.Deserialize <UDPLogin>(tempMessageContent);
            login.login = strPoint;
            allUDPs[strPoint].roomID = login.roomID;
            allUDPs[strPoint].unique = login.unique;
            Log4Debug("UDP login 房间号:" + login.roomID);
            newBuffer = SerializeHelper.Serialize <UDPLogin>(login);
            break;

        case MessageConvention.moveDirection:
            moveDirection = SerializeHelper.Deserialize <ActorMoveDirection>(tempMessageContent);
            if (room.ActorList[moveDirection.userIndex].CurState != RoomActorState.Dead)
            {
                //Log4Debug("将历史帧:" + moveDirection.frameIndex + "保存到" + (moveDirection.frameIndex + room.RoomInfo.frameInterval) + "/" + room.RoomInfo.FrameIndex);
                room.SetRecondFrame(xieyi.ToBytes());
                //Log4Debug("站位:" + moveDirection.userIndex + " 更新了方向:" + "["
                //    + moveDirection.direction.x + ","
                //    + moveDirection.direction.y + ","
                //    + moveDirection.direction.z + "]"
                //    + "/速度:" + moveDirection.speed);
            }
            else
            {
                Log4Debug("死亡用户不更新移动。");
            }
            break;

        case MessageConvention.rotateDirection:
            ActorRotateDirection netRotation = SerializeHelper.Deserialize <ActorRotateDirection>(tempMessageContent);
            if (room.ActorList[netRotation.userIndex].CurState != RoomActorState.Dead)
            {
                room.SetRecondFrame(xieyi.ToBytes());
                //Log4Debug("站位:" + netRotation.userIndex + " 更新了旋转:" + netRotation.rotateY);
            }
            else
            {
                Log4Debug("死亡用户不更新旋转。");
            }
            break;

        case MessageConvention.jump:
            ActorJump netJump = SerializeHelper.Deserialize <ActorJump>(tempMessageContent);
            if (room.ActorList[netJump.userIndex].CurState != RoomActorState.Dead)
            {
                room.SetRecondFrame(xieyi.ToBytes());
            }
            else
            {
                Log4Debug("死亡用户不更新跳跃。");
            }
            break;

        case MessageConvention.shootBullet:
            ShootInfo shootInfo = SerializeHelper.Deserialize <ShootInfo>(tempMessageContent);
            if (room.ActorList[shootInfo.userIndex].CurState != RoomActorState.Dead)
            {
                room.SetRecondFrame(xieyi.ToBytes());
                //Log4Debug("站位:" + netRotation.userIndex + " 更新了旋转:" + netRotation.rotateY);
            }
            else
            {
                Log4Debug("死亡用户不更新射击。");
            }
            break;

        case MessageConvention.bulletInfo:
            //
            BulletInfo bulletInfo = SerializeHelper.Deserialize <BulletInfo>(xieyi.MessageContent);
            room.UpdateBulletInfo(bulletInfo);    //更新
            //room.SetRecondFrame(xieyi.ToBytes());
            break;

        default:
            Log4Debug("检查协议->" + (MessageConvention)xieyi.XieYiFirstFlag);
            break;
        }

        byte[] sendBuffer = null;
        if (newBuffer != null)//用户需要服务器返回值给自己的话
        {
            xieyi      = new MessageXieYi(xieyi.XieYiFirstFlag, xieyi.XieYiSecondFlag, newBuffer);
            sendBuffer = xieyi.ToBytes();
        }
        return(sendBuffer);
    }
Пример #23
0
    public byte[] CreateNewRoom(JObject json, AsyncUserToken userToken)
    {
        byte[]   backData = null;
        JoinRoom joinInfo = new JoinRoom()
        {
            error = ErrorType.none, roomID = -1, unique = -1
        };
        GameModel roomType = (GameModel)(int)json[nameof(RoomInfo.RoomType)];
        string    roomName = (string)json[nameof(RoomInfo.RoomName)];

        //主逻辑
        string userName = userToken.userInfo.Register.name;

        if (roomName == null)
        {
            roomName = userName + "的房间";
        }
        Log4Debug("当前房间数:" + RoomList.Values.Count);

        foreach (var item in RoomList)
        {
            if (item.Key == 0)//0号房间为默认房间,防止出错,不作为用户房间使用
            {
                continue;
            }
            SingleRoom singleRoom = new SingleRoom(item.Key, (string)roomName, roomType);
            if (RoomList.GetOrAdd(item.Key, (value) => singleRoom).IsEmptyRoom())//创建房间成功
            {
                RoomList.TryGetValue(item.Key, out singleRoom);
                if (singleRoom.Join(userToken, out joinInfo.unique))
                {
                    joinInfo.roomID = item.Key;
                    Log4Debug("空房间{0}作为新建房间成功。" + item.Key);
                    break;
                }
                else
                {
                    Log4Debug("该空房间{0}不可加入,请检查。" + item.Key);
                }
            }
        }
        while (joinInfo.roomID < 0)//遍历存在键值后依旧没有房间可用
        {
            int        roomID     = -1;
            SingleRoom singleRoom = null;
            lock (RoomList)
            {
                roomID     = RoomList.Count;
                singleRoom = new SingleRoom(roomID, (string)roomName, roomType);
                RoomList.GetOrAdd(roomID, (value) => singleRoom);
                //
                joinInfo.roomID = roomID;
            }

            if (singleRoom.Join(userToken, out joinInfo.unique))
            {
                joinInfo.roomID = roomID;
                Log4Debug("创建并加入新房间{0}成功" + roomID);
                break;
            }
        }
        backData = SerializeHelper.Serialize <JoinRoom>(joinInfo);
        return(backData);
    }
Пример #24
0
    /// <summary>
    /// tcp
    /// </summary>
    /// <param name="xieyi"></param>
    /// <param name="userToken"></param>
    /// <returns></returns>
    public byte[] SelectMessage(MessageXieYi xieyi, AsyncUserToken userToken)
    {
        JObject json = null;

        byte[]             newBuffer          = null;
        byte[]             tempMessageContent = xieyi.MessageContent;
        int                roomID             = userToken.userInfo.RoomID;
        SingleRoom         room            = GetSingleRoomByID(roomID);
        Register           login           = null;
        RoomActorUpdate    roomActorUpdate = null;
        ActorMoveDirection moveDirection   = null;

        if (userToken == null)
        {
            Log4Debug("该用户已被清理,不处理接收数据。");
            return(newBuffer);
        }
        if (allRoom.RoomList.ContainsKey(userToken.userInfo.RoomID))
        {
            room = allRoom.RoomList[userToken.userInfo.RoomID];
        }

        //Log4Debug("/" + xieyi.MessageContentLength);
        //try
        {
            switch ((MessageConvention)xieyi.XieYiFirstFlag)
            {
            case MessageConvention.login:
                login     = SerializeHelper.Deserialize <Register>(tempMessageContent);
                newBuffer = Login(login, userToken);
                break;

            case MessageConvention.getHeartBeatTime:
                HeartbeatTime hbTime = new HeartbeatTime()
                {
                    time = AsyncIOCPServer.HeartbeatSecondTime
                };
                newBuffer = SerializeHelper.Serialize <HeartbeatTime>(hbTime);
                break;

            case MessageConvention.reConnectCheck:
                //检查是否是掉线用户
                ReconnctInfo rcInfo = new ReconnctInfo();
                if (OffLineRooms.ContainsKey(userToken.userInfo.Register.userID))
                {
                    int offRoomID = OffLineRooms[userToken.userInfo.Register.userID];
                    userToken.userInfo.RoomID = offRoomID;
                    allRoom.RoomList[offRoomID].ReConnect(userToken);

                    int removeCount = 0;
                    OffLineRooms.TryRemove(userToken.userInfo.Register.userID, out removeCount);
                    rcInfo.isReconnect = true;
                }
                else
                {
                    rcInfo.isReconnect = false;
                }
                newBuffer = SerializeHelper.Serialize <ReconnctInfo>(rcInfo);
                break;

            case MessageConvention.reConnectIndex:
                room.GetReConnectFrameData(userToken.userInfo.UniqueID);
                break;

            case MessageConvention.heartBeat:
                //心跳检测客户端传递服务器时间
                //Log4Debug("接收到 " + userToken.userInfo.Register.name + " 的心跳检测");
                //newBuffer = SerializeHelper.DateTimeToBytes(DateTime.Now);
                //newBuffer = SerializeHelper.Serialize<HeartbeatTime>(new HeartbeatTime() { time = AsyncIOCPServer.HeartbeatSecondTime });
                break;

            case MessageConvention.updateName:
                string updateName = SerializeHelper.ConvertToString(tempMessageContent);
                Log4Debug("修改人物信息:" + updateName);
                newBuffer = UpdateName(userToken, updateName);
                break;

            case MessageConvention.createRoom:
                json      = JObject.Parse(SerializeHelper.ConvertToString(xieyi.MessageContent));
                newBuffer = allRoom.CreateNewRoom(json, userToken);
                break;

            case MessageConvention.joinRoom:
                json      = JObject.Parse(SerializeHelper.ConvertToString(xieyi.MessageContent));
                newBuffer = allRoom.JoinRoom(json, userToken);
                break;

            case MessageConvention.updateRoom:
                Log4Debug("更新房间");
                json      = JObject.Parse(SerializeHelper.ConvertToString(xieyi.MessageContent));
                newBuffer = allRoom.UpdateRoom(json);
                break;

            case MessageConvention.getRoomInfo:
                newBuffer = SerializeHelper.Serialize <RoomInfo>(room.RoomInfo);
                break;

            case MessageConvention.getRoommateInfo:
                Log4Debug("请求房间人物信息:" + SerializeHelper.ConvertToString(tempMessageContent));
                roomActorUpdate = new RoomActorUpdate();
                roomActorUpdate.SetSendInfo(SerializeHelper.ConvertToString(tempMessageContent));
                //
                newBuffer = SerializeHelper.Serialize <List <RoomActor> >(new List <RoomActor>(room.ActorList.Values));
                break;

            case MessageConvention.quitRoom:
                QuitInfo qInfo = SerializeHelper.Deserialize <QuitInfo>(tempMessageContent);
                if (room != null)
                {
                    room.CheckQuit(userToken, qInfo);
                }
                break;

            case MessageConvention.updateActorAnimation:
                ActorNetAnimation netAnimation = new ActorNetAnimation();
                netAnimation.SetSendInfo(SerializeHelper.ConvertToString(tempMessageContent));
                //Log4Debug("set->" + netAnimation.animationIndex + "");
                room.UpdateAnimation(netAnimation);    //更新
                break;

            case MessageConvention.updateActorState:
                roomActorUpdate = new RoomActorUpdate();
                roomActorUpdate.SetSendInfo(SerializeHelper.ConvertToString(tempMessageContent));
                Log4Debug("站位:" + userToken.userInfo.UniqueID + "/" + userToken.userInfo.Register.name
                          + "用户站位:" + roomActorUpdate.userIndex +
                          "请求修改状态为->" + (RoomActorState)int.Parse(roomActorUpdate.update));
                //
                room.UpdateState(roomActorUpdate);    //更新
                break;

            case MessageConvention.prepareLocalModel:
                roomActorUpdate = new RoomActorUpdate();
                roomActorUpdate.SetSendInfo(SerializeHelper.ConvertToString(tempMessageContent));
                //
                room.UpdatePrepare(roomActorUpdate, userToken);    //更新
                break;

            case MessageConvention.getPreGameData:

                break;

            case MessageConvention.startGaming:

                break;

            case MessageConvention.endGaming:

                break;

            case MessageConvention.frameData:
                FrameInfo frame = SerializeHelper.Deserialize <FrameInfo>(tempMessageContent);
                newBuffer = room.GetBoardFrame(frame.frameIndex);
                //Log4Debug("用户" + userToken.userInfo.Register.name + "/请求帧数据:" + frame.frameIndex + "/" + room.RoomInfo.FrameIndex + "数据总长:" + newBuffer.Length);
                break;

            //case MessageConvention.setUDP:
            //    UDPLogin loginUDP = SerializeHelper.Deserialize<UDPLogin>(tempMessageContent);
            //    Log4Debug("收到登录UDP账号:" + loginUDP.login);
            //    room.UpdateUDP(userToken.userInfo.UniqueID, loginUDP);
            //    break;
            default:
                Log4Debug("TCP是否判断该协议:" + (MessageConvention)xieyi.XieYiFirstFlag);
                break;
            }
        }
        //catch (Exception error)
        //{
        //    Log4Debug("处理逻辑错误:" + error.Message);
        //}
        //  创建一个发送缓冲区。
        byte[] sendBuffer = null;
        if (newBuffer != null)//用户需要服务器返回值给自己的话
        {
            xieyi      = new MessageXieYi(xieyi.XieYiFirstFlag, xieyi.XieYiSecondFlag, newBuffer);
            sendBuffer = xieyi.ToBytes();
        }
        return(sendBuffer);
    }
Пример #25
0
    public byte[] JoinRoom(JObject json, AsyncUserToken userToken)
    {
        byte[]   backData = null;
        JoinRoom joinInfo = new JoinRoom()
        {
            error = ErrorType.none, roomID = -1, unique = -1
        };
        string    roomID   = (string)json[nameof(RoomInfo.RoomID)];
        GameModel roomType = (GameModel)(int)json[nameof(RoomInfo.RoomType)];

        //主逻辑
        if (!string.IsNullOrEmpty(roomID))//加入指定房间
        {
            joinInfo.roomID = int.Parse(roomID);
            SingleRoom singleRoom = null;
            if (RoomList.TryGetValue(joinInfo.roomID, out singleRoom))
            {
                if (singleRoom.CurState == RoomActorState.Gaming)
                {
                    joinInfo.error = ErrorType.roomIsGaming;
                }
                else if (singleRoom.Join(userToken, out joinInfo.unique))//可以加入
                {
                    Log4Debug("加入指定ID房间成功。");
                }
                else
                {
                    joinInfo.error = ErrorType.roomMateFull;
                }
            }
            else
            {
                joinInfo.error = ErrorType.roomNotExist;
            }
        }
        else//根据游戏类型遍历所有房间
        {
            foreach (var item in RoomList)
            {
                if (item.Key == 0)
                {
                    continue;
                }
                if (item.Value.RoomInfo.RoomType != roomType)
                {
                    continue;
                }
                if (item.Value.Join(userToken, out joinInfo.unique))//可以加入
                {
                    joinInfo.roomID = item.Key;
                    Log4Debug("加入游戏类型房间成功。");
                    continue;
                }
            }
            if (joinInfo.roomID < 0)
            {
                //请求加入的游戏模式暂没有房间,生成新房间
                backData = CreateNewRoom(json, userToken);
            }
        }
        backData = SerializeHelper.Serialize <JoinRoom>(joinInfo);
        return(backData);
    }
Пример #26
0
        static void Main(string[] args)
        {
            string estate;
            int    sf;
            string location;

            Console.WriteLine("Welcome!!");
            Console.WriteLine("Tell us what tipe of place you are looking for.");
            Console.WriteLine("House");
            Console.WriteLine("Apartment");
            Console.WriteLine("SingleRoom");
            Console.WriteLine("Land");
            estate = Console.ReadLine();
            if (estate == "House")
            {
                Console.WriteLine("How many square feet do you want your house to be ?");
                sf = int.Parse(Console.ReadLine());
                Console.WriteLine("Choose the location you prefer (center or suburbs)");
                location = Console.ReadLine();
                House house = new House(sf, location);

                var price      = new HouseBasePrice();
                var calculator = new HouseComissionCalculator();

                Prices.GetLocation(house, location);
                Prices.GetInitialPrice(house, price);
                Prices.GetComission(house, calculator, price);
                Prices.GetPrice(house, calculator, price);
            }
            if (estate == "Apartment")
            {
                Console.WriteLine("How many square feet do you want your house to be ?");
                sf = int.Parse(Console.ReadLine());
                Console.WriteLine("Choose the location you prefer (center or suburbs)");
                location = Console.ReadLine();
                Apartment apartment = new Apartment(sf, location);

                var price      = new ApartmentBasePrice();
                var calculator = new ApartmentComissionCalculator();

                Prices.GetLocation(apartment, location);
                Prices.GetInitialPrice(apartment, price);
                Prices.GetComission(apartment, calculator, price);
                Prices.GetPrice(apartment, calculator, price);
            }
            if (estate == "SingleRoom")
            {
                Console.WriteLine("How many square feet do you want your house to be ?");
                sf = int.Parse(Console.ReadLine());
                Console.WriteLine("Choose the location you prefer (center or suburbs)");
                location = Console.ReadLine();
                SingleRoom singleroom = new SingleRoom(sf, location);

                var price      = new SingleRoomBasePrice();
                var calculator = new SingleRoomComissionCalculator();

                Prices.GetLocation(singleroom, location);
                Prices.GetInitialPrice(singleroom, price);
                Prices.GetComission(singleroom, calculator, price);
                Prices.GetPrice(singleroom, calculator, price);
            }
            if (estate == "Land")
            {
                Console.WriteLine("How many square feet do you want your house to be ?");
                sf = int.Parse(Console.ReadLine());
                Console.WriteLine("Tell us the cadastral number: 4578/ 3463/ 2098");
                int  cadastral_nr = int.Parse(Console.ReadLine());
                Land land         = new Land(sf, cadastral_nr);

                var price      = new LandBasePrice();
                var calculator = new LandComissionCalculator();

                Prices.GetLocationLand(land, cadastral_nr);
                Prices.GetInitialPrice(land, price);
                Prices.GetComission(land, calculator, price);
                Prices.GetPrice(land, calculator, price);
            }
        }
 // 外部设置房间
 public void SetRoom(int i, int j, SingleRoom room)
 {
     rooms[i][j] = room;
 }
Пример #28
0
        public void gameOver(int userId, SingleRoom room, int whichwin)
        {
            UserModel     um     = userCache.GetModelById(userId);
            ClientPeer    client = userCache.GetClientPeer(userId);
            int           wager  = room.Wager;
            SingleOverDto odto   = new SingleOverDto();



            switch (whichwin)
            {
            case 1:
            {
                int dealerWeight = room.GetDealerWeight();
                odto.dealerWeight = dealerWeight;
                //21点,和庄家比 获胜或平局
                if (dealerWeight != 21)        //获胜
                {
                    um.Been         += (int)(1.5 * wager);
                    um.Exp          += 150;
                    odto.dealerState = 3;
                    odto.playerStateList.Add(1);
                    odto.playerWeightList.Add(room.GetPlayerWeight());
                    odto.playerWinBeenList.Add((int)(1.5 * wager));
                }
                else
                {
                    um.Exp          += 75;
                    odto.dealerState = 1;
                    odto.playerStateList.Add(0);
                    odto.playerWeightList.Add(room.GetPlayerWeight());
                    odto.playerWinBeenList.Add((int)(0));
                }
                break;
            }



            case 2:    //闲家爆牌
            case 4:    //庄家获胜
            {
                int dealerWeight = room.GetDealerWeight();
                odto.dealerWeight = dealerWeight;
                odto.dealerState  = 3;
                um.Been          -= wager * room.Multiple;
                um.Exp           += 50;
                odto.playerWeightList.Add(room.GetPlayerWeight());
                odto.playerWinBeenList.Add(-(wager * room.Multiple));

                if (room.Multiple == 2)
                {
                    if (room.GetPlayerWeight() > 21)     //加倍爆牌
                    {
                        odto.playerStateList.Add(3);
                    }
                    else
                    {
                        odto.playerStateList.Add(5);        //加倍输
                    }
                }
                else
                {
                    if (room.GetPlayerWeight() > 21)        //加倍爆牌
                    {
                        odto.playerStateList.Add(2);
                    }
                    else
                    {
                        odto.playerStateList.Add(7);        //加倍输
                    }
                }

                break;
            }

            case 3:    //庄家爆牌,闲家获胜
            case 5:
            {
                int dealerWeight = room.GetDealerWeight();
                odto.dealerWeight = dealerWeight;
                if (room.GetDealerWeight() > 21)     //爆牌
                {
                    odto.dealerState = 2;
                }
                else
                {
                    odto.dealerState = 3;
                }


                um.Been += wager * room.Multiple;
                odto.playerWinBeenList.Add(wager * room.Multiple);
                odto.playerWeightList.Add(room.GetPlayerWeight());
                if (room.Multiple == 2)      //加倍赢
                {
                    odto.playerStateList.Add(4);
                }
                else
                {
                    odto.playerStateList.Add(6);        //赢
                }
                um.Exp += 100;
                break;
            }

            case 6:
            {
                int dealerWeight = room.GetDealerWeight();
                odto.dealerWeight = dealerWeight;
                odto.dealerState  = 3;
                odto.playerWinBeenList.Add(0);
                odto.playerWeightList.Add(room.GetPlayerWeight());
                odto.playerStateList.Add(8);        //平
                um.Exp += 75;
                break;
            }

            case 7:
            {
                //看看是不是全爆牌了
                bool isallboom = room.isAllBoom();

                //这个是让客户端翻面
                client.Send(OpCode._21Single, _21SingleCode.NGET_SRES, null);
                if (!isallboom)
                {
                    while (room.GetDealerWeight() < 17)
                    {
                        CardDto carddto = room.GetOneDealerCard();
                        client.Send(OpCode._21Single, _21SingleCode.ADD_DCARD_SRES, carddto);
                    }
                }
                int dealerWeight = room.GetDealerWeight();
                odto.dealerWeight = dealerWeight;

                if (room.DealerCardList.Count == 2 && room.GetDealerWeight() == 21)        //庄家是21点
                {
                    odto.dealerState = 1;
                }
                else if (room.GetDealerWeight() > 21)
                {
                    odto.dealerState = 2;
                }
                else
                {
                    odto.dealerState = 3;
                }

                for (int j = 0; j < room.player.SpliteCardListList.Count; j++)
                {
                    int multi = 1;

                    PlayerCardDto tempPlayerCardDto = room.player.SpliteCardListList[j];
                    int           tempWeight        = tempPlayerCardDto.Weight;
                    odto.playerWeightList.Add(tempWeight);

                    int  tempState    = tempPlayerCardDto.CardState;
                    bool tempIsDouble = tempPlayerCardDto.isDouble;
                    if (tempIsDouble)
                    {
                        multi = 2;
                    }


                    //21点
                    if (tempState == 1)
                    {
                        if (dealerWeight == 1)     //平局
                        {
                            odto.playerWinBeenList.Add(0);
                            odto.playerStateList.Add(0);
                            um.Exp += 75;
                        }
                        else
                        {
                            um.Been += (int)(wager * 1.5);
                            odto.playerWinBeenList.Add((int)(wager * 1.5));
                            odto.playerStateList.Add(1);

                            um.Exp += 150;
                        }
                    }
                    //闲家爆牌
                    else if (tempState == 2)
                    {
                        um.Been -= wager * multi;
                        odto.playerWinBeenList.Add(-wager * multi);
                        if (multi == 1)
                        {
                            odto.playerStateList.Add(2);
                        }
                        else
                        {
                            odto.playerStateList.Add(3);
                        }
                        um.Exp += 50;
                    }
                    //不要 权值小于
                    else if (tempState == 3)
                    {
                        //庄家爆牌
                        if (dealerWeight > 21)
                        {
                            um.Been += wager * multi;
                            odto.playerWinBeenList.Add(wager * multi);
                            if (multi == 1)
                            {
                                odto.playerStateList.Add(6);
                            }
                            else
                            {
                                odto.playerStateList.Add(4);
                            }

                            um.Exp += 100;
                        }
                        //闲家点大
                        else if (dealerWeight < tempWeight)
                        {
                            um.Been += wager * multi;
                            odto.playerWinBeenList.Add(wager * multi);
                            if (multi == 1)
                            {
                                odto.playerStateList.Add(6);
                            }
                            else
                            {
                                odto.playerStateList.Add(4);
                            }
                            um.Exp += 100;
                        }
                        //庄家点大
                        else if (dealerWeight > tempWeight)
                        {
                            um.Been -= wager * multi;
                            odto.playerWinBeenList.Add(-wager * multi);
                            if (multi == 1)
                            {
                                odto.playerStateList.Add(7);
                            }
                            else
                            {
                                odto.playerStateList.Add(5);
                            }
                            um.Exp += 50;
                        }
                        //平局
                        else
                        {
                            odto.playerWinBeenList.Add(0);
                            odto.playerStateList.Add(8);

                            um.Exp += 75;
                        }
                    }
                }

                //double sum = room.computeWinOrLoss();
                //um.Been += (int)(sum * wager);


                //um.Exp += 50 * room.player.SplitNum;
                //清理工作
                room.player.SplitNum = 1;
                room.splitClear();

                break;
            }


            default:
                break;
            }
            int maxExp = um.Lv * 100;

            while (maxExp <= um.Exp)
            {
                um.Lv++;
                um.Exp -= maxExp;
                maxExp  = um.Lv * 100;
            }
            userCache.Update(um);
            UserDto dto = new UserDto(um.Id, um.Name, um.Been, um.WinCount, um.LoseCount, um.RunCount, um.Lv, um.Exp);

            //SingleOverDto odto = new SingleOverDto(dto, whichwin);
            odto.userDto = dto;
            client.Send(OpCode._21Single, _21SingleCode.OVER_SRES, odto);
            room.player.CardList.Clear();
            room.DealerCardList.Clear();
            Thread.Sleep(100);
            CountStrategyDto countStrategyDto = room.libraryModel.GetCountStrategyDto();

            client.Send(OpCode._21Single, _21SingleCode.COUNT_STRATEGY_SRES, countStrategyDto);
        }
Пример #29
0
        /// <summary>
        /// 加倍
        /// </summary>
        /// <param name="client"></param>
        public void doubleCard(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                //必须确保在线
                int userId = userCache.GetId(client);

                SingleRoom room = singleCache.GetRoomByUId(userId);

                CardDto dto = room.GetOnePlayerCard();
                client.Send(OpCode._21Single, _21SingleCode.GET_SRES, dto);
                //说明是分牌的
                if (room.player.SplitNum > 1)
                {
                    if (room.GetPlayerWeight() > 21)    //闲家爆牌 这局结束
                    {
                        room.SaveList(2, true);
                        client.Send(OpCode._21Single, _21SingleCode.SPLIT_PROMST_SRES, 2);    //闲家爆牌
                        //room.player.SpliteCardListList.Add(room.player.CardList);
                        if (room.player.SpliteCardListQueue.Count() > 0)
                        {
                            //room.player.winOrLose.Add(-2);//加倍的时候爆牌了,所以是-2
                            client.Send(OpCode._21Single, _21SingleCode.SPLIT_CAN_NEXT_SRES, null);
                        }
                        else
                        {
                            gameOver(userId, room, 7);
                        }
                    }
                    else
                    {
                        //room.addWeightAndMulti(2);
                        room.SaveList(3, true);
                        //client.Send(OpCode._21Single, _21SingleCode.SPLIT_PROMST_SRES, whichwin);
                        //先不能判断输赢
                        if (room.player.SpliteCardListQueue.Count() > 0)
                        {
                            client.Send(OpCode._21Single, _21SingleCode.SPLIT_PROMST_SRES, 0);    //随便提示一下

                            client.Send(OpCode._21Single, _21SingleCode.SPLIT_CAN_NEXT_SRES, null);
                        }
                        else
                        {
                            gameOver(userId, room, 7);
                        }
                    }
                }
                else
                {
                    //设置倍数
                    room.Multiple = 2;
                    if (room.GetPlayerWeight() > 21)    //闲家爆牌 这局结束
                    {
                        //client.Send(OpCode._21Single, _21SingleCode.OVER_SRES, 2);
                        client.Send(OpCode._21Single, _21SingleCode.NGET_SRES, null);
                        gameOver(userId, room, 2);
                    }
                    else
                    {
                        client.Send(OpCode._21Single, _21SingleCode.NGET_SRES, null);
                        while (room.GetDealerWeight() < 17)
                        {
                            CardDto dto2 = room.GetOneDealerCard();
                            client.Send(OpCode._21Single, _21SingleCode.ADD_DCARD_SRES, dto2);
                        }

                        int whichwin = room.whichWin();
                        //client.Send(OpCode._21Single, _21SingleCode.OVER_SRES, whichwin);
                        gameOver(userId, room, whichwin);
                    }
                }
            });
        }