private int RefreshUsersList() { Dispatcher.BeginInvoke(new Action(() => { users_panel.Children.Clear(); })); string answer = Communicator.Send("", (byte)ReqCode.GETROOMSTATE); answer = answer.Substring(answer.IndexOf('{'), answer.IndexOf('}') - 4); // we use that as a GetUsersInRoomResponse GetRoomStateResponse response = JsonConvert.DeserializeObject <GetRoomStateResponse>(answer); string[] users = response.players.Split(','); if (users[0] == "" && users.Length == 1) { return(-1); } foreach (string user in users) { Dispatcher.BeginInvoke(new Action(() => { TextBlock textBlock = new TextBlock { Text = user, FontSize = 20, FontFamily = new System.Windows.Media.FontFamily("Tempus Sans ITC"), Margin = new Thickness(5) }; users_panel.Children.Add(textBlock); })); } return(response.hasGameBegun); }
protected void RoomBtnClicked(object sender, RoutedEventArgs e) { uint id = uint.Parse(((Button)sender).Name.Substring(1)); string roomName = (string)((Button)sender).Content; JoinRoomResponse response = (JoinRoomResponse)Communicator.Communicate(new JoinRoomRequest(id)); GetRoomStateResponse res = (GetRoomStateResponse)Communicator.Communicate(new GetRoomStateRequest()); Room room = new Room(roomName, (uint)res.players.Split(',').Length, res.questionCount, res.answerTimeOut); if (response.status == 1) { WaitingRoomWindow wind = new WaitingRoomWindow(false, this.username, res.players.Split(','), room); wind.Show(); this.Hide(); this.Close(); } }
/* * The function will rapidly ask the server to send the players list so it will be updated // Might be a thread * input: none * output: none */ private void RefreshPlayersList() { GetRoomStateResponse response = (GetRoomStateResponse)Communicator.Communicate(new GetRoomStateRequest()); string[] newList = response.players.Split(','); if (newList == null) { return; } this.state = response.state; if (!IsSamePlayers(newList)) { this.players = newList; this.room.numberOfPlayers = (uint)players.Length; FillTBs(); } }