Esempio n. 1
0
        public WaitingRoomInformation MakeWaitingRoomPacket()
        {
            WaitingRoomInformation packet = new WaitingRoomInformation
            {
                SendDate = DateTime.UtcNow
            };

            return(packet);
        }
Esempio n. 2
0
        public WaitingRoomInformation GetWaitingRoomInformation()
        {
            WaitingRoomInformation waitingRoomInfo = new WaitingRoomInformation
            {
                RoomCount = _activeRooms.Count,
                Rooms     = new RoomInformation[_activeRooms.Count]
            };

            int count = 0;

            foreach (var room in _activeRooms)
            {
                waitingRoomInfo.Rooms[count] = room.GetRoomInformation();
                count++;
            }

            return(waitingRoomInfo);
        }
        private void Client_OnWaitingRoomInformationRecieved(WaitingRoomInformation packet)
        {
            WaitingRoomInformation waitingRoom = packet;

            _waitingRoom = waitingRoom;

            List <GameRoomUIItem> newItems = new List <GameRoomUIItem>();

            RoomInformation joinedRoom = null;

            if (_waitingRoom != null && _waitingRoom.Rooms != null)
            {
                int startYPos = _roomStartYPos;
                foreach (var room in _waitingRoom.Rooms)
                {
                    GameRoomUIItem uiItem = new GameRoomUIItem();
                    uiItem.Rect = new Rectangle(50, startYPos, 500, 50);

                    switch ((GameRoomState)room.RoomState)
                    {
                    case GameRoomState.Waiting:
                        uiItem.Text = room.RoomName + " : " + room.ConnectionCount + "/" + WaitingRoom.MAX_PEOPLE_PER_ROOM + " Players";
                        break;

                    case GameRoomState.InSession:
                        uiItem.Text = room.RoomName + " : PLAYING";
                        break;

                    case GameRoomState.Leaderboards:
                        uiItem.Text = room.RoomName + " : GAME FINISHING";
                        break;
                    }

                    Vector2 size   = _font.MeasureString(uiItem.Text);
                    float   xScale = (uiItem.Rect.Width / size.X);
                    float   yScale = (uiItem.Rect.Height / size.Y);
                    float   scale  = Math.Min(xScale, yScale);

                    // Figure out the location to absolutely-center it in the boundaries rectangle.
                    int strWidth  = (int)Math.Round(size.X * scale);
                    int strHeight = (int)Math.Round(size.Y * scale);

                    // Set Position
                    uiItem.Position = new Vector2
                    {
                        X = (((uiItem.Rect.Width - strWidth) / 2) + uiItem.Rect.X),
                        Y = (((uiItem.Rect.Height - strHeight) / 2) + uiItem.Rect.Y)
                    };

                    // Set border options
                    uiItem.BorderColour = Color.Blue;
                    uiItem.BorderWidth  = 1;

                    newItems.Add(uiItem);
                    startYPos += 50;

                    if (room.RoomID == _joinedRoomID)
                    {
                        joinedRoom = room;
                    }
                }
            }

            _roomUIItems = newItems;

            if (joinedRoom != null)
            {
                if (joinedRoom.ConnectionCount == 1)
                {
                    _buttonText  = "WAITING FOR MORE PLAYERS";
                    _state       = WaitingRoomState.InRoomWaitingForPlayers;
                    _readyToPlay = false;
                }
                else
                {
                    if (!_readyToPlay)
                    {
                        _buttonText = "CLICK TO READY (" + joinedRoom.ReadyCount + "/" + joinedRoom.ConnectionCount + ")";
                        _state      = WaitingRoomState.InRoomNotReady;
                    }
                    else
                    {
                        _buttonText = "READY TO PLAY! (" + joinedRoom.ReadyCount + "/" + joinedRoom.ConnectionCount + ")";
                        _state      = WaitingRoomState.InRoomReady;
                    }
                }
            }
            else
            {
                if (_roomUIItems.Count < Server.MAX_ROOMS)
                {
                    _buttonText = "CREATE NEW ROOM";
                    _state      = WaitingRoomState.NotInRoomAbleToCreate;
                }
                else
                {
                    _buttonText = "UNABLE TO CREATE NEW ROOM";
                    _state      = WaitingRoomState.NotInRoomUnableToCreate;
                }
            }

            ReformatButton();
        }