public RoomInformation MakeRoomInformationPacket(string roomName, string roomID, List <ServerConnection> connections, int readyCount, GameRoomState roomState) { RoomInformation packet = new RoomInformation { SendDate = DateTime.UtcNow, RoomName = roomName, RoomID = roomID, ReadyCount = readyCount, ConnectionCount = connections.Count, RoomState = (int)roomState }; packet.ConnectionIDs = new string[packet.ConnectionCount]; packet.ConnectionNames = new string[packet.ConnectionCount]; for (int i = 0; i < packet.ConnectionCount; i++) { packet.ConnectionIDs[i] = connections[i].ID; packet.ConnectionNames[i] = connections[i].Name; } return(packet); }
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(); }