public BeforeGameWindow(string room_name, bool is_admin) { InitializeComponent(); TextBlock title = new TextBlock(); title.FontSize = 30; title.Margin = new Thickness(101, 30, 0, 0); title.Inlines.Add(new Underline(new Bold(new Run("Conected to " + room_name)))); BeforeGameWindowCanvas.Children.Add(title); string request = Constants.GET_ROOM_STATE_ID.ToString() + "0"; string response = helper.SendAndRecive(request); GetRoomStateResponse getRoomStateResponse = new JavaScriptSerializer().Deserialize <GetRoomStateResponse>(response); TextBlock textBlock = new TextBlock(); textBlock.FontSize = 23; textBlock.Foreground = Brushes.Blue; textBlock.Margin = new Thickness(534, 175, 0, 0); textBlock.Inlines.Add(new Bold(new Run("Room Detailes"))); BeforeGameWindowCanvas.Children.Add(textBlock); this.question_count = getRoomStateResponse.question_count; this.answer_timeout = getRoomStateResponse.answer_timeout; add_textBlock(new Thickness(534, 225, 0, 0), "Number Of Question - " + getRoomStateResponse.question_count.ToString()); add_textBlock(new Thickness(534, 275, 0, 0), "Time Per Question - " + getRoomStateResponse.answer_timeout.ToString()); foreach (string player in getRoomStateResponse.players) { ListBoxItem listBoxItem = new ListBoxItem(); listBoxItem.Content = player; playersList.Items.Add(listBoxItem); } set_buttons(is_admin); }
private void set_question() { string request = Constants.GET_QUESTION_ID.ToString() + "0"; string response = helper.SendAndRecive(request); GetQuestionResponse getQuestionResponse = new JavaScriptSerializer().Deserialize <GetQuestionResponse>(response); if (getQuestionResponse.status == Constants.SUCCESS_STATUS) { questionTextBlock.Text = getQuestionResponse.question;//set question try { firstAnswer.Content = getQuestionResponse.answers[0]; //set first optional answer secondAnswer.Content = getQuestionResponse.answers[1]; //set second optional answer thirdAnswer.Content = getQuestionResponse.answers[2]; //set third optional answer fourthAnswer.Content = getQuestionResponse.answers[3]; //set fourth optional answer } catch { } firstAnswer.Foreground = Brushes.Black; secondAnswer.Foreground = Brushes.Black; thirdAnswer.Foreground = Brushes.Black; fourthAnswer.Foreground = Brushes.Black; firstAnswer.FontWeight = FontWeights.Bold; //making the text bold secondAnswer.FontWeight = FontWeights.Bold; //making the text bold thirdAnswer.FontWeight = FontWeights.Bold; //making the text bold fourthAnswer.FontWeight = FontWeights.Bold; //making the text bold } }
private void CreateClick(object sender, RoutedEventArgs e) { string room_name = room_name_box.Text; int max_players; int question_count; int answer_timeout; if (int.TryParse(number_of_players_box.Text, out max_players)) { if (int.TryParse(number_of_players_box.Text, out question_count)) { if (int.TryParse(number_of_players_box.Text, out answer_timeout)) { CreateRoomRequest createRoomRequest = new CreateRoomRequest(room_name, max_players, question_count, answer_timeout); var json = new JavaScriptSerializer().Serialize(createRoomRequest); string request = Constants.CREATE_ROOM_ID.ToString() + json.Length.ToString() + json; string response = helper.SendAndRecive(request); CreateRoomResponse createRoomResponse = new JavaScriptSerializer().Deserialize <CreateRoomResponse>(response); BeforeGameWindow beforeGameWindow = new BeforeGameWindow(room_name, true); beforeGameWindow.Show(); this.Close(); } } } else { } }
private void LoginInClick(object sender, RoutedEventArgs e) { string username = usernameTextBox.Text; string password = passwordBox.Password; if (helper.validate_input(username) && helper.validate_input(password)) { LoginRequest login_request = new LoginRequest(username, password); var json = new JavaScriptSerializer().Serialize(login_request); string msg = Constants.LOGIN_ID.ToString() + json.Length.ToString() + json; string response = helper.SendAndRecive(msg); LoginResponse loginResponse = new JavaScriptSerializer().Deserialize <LoginResponse>(response); if (loginResponse.status == Constants.SUCCESS_STATUS)//success status { Helper.set_username(username); MenuWindow menuWindow = new MenuWindow(); menuWindow.Show(); this.Close(); //MessageBox.Show("Success!"); } else { MessageBox.Show("Try again!"); } } else { MessageBox.Show("input contain only latters and digits"); } }
private void get_rooms() { room_detailes.Clear(); string request = Constants.GET_ROOMS_ID.ToString() + "0"; string response = helper.SendAndRecive(request); MessageBox.Show(response); //GetRoomResponse roomResponse= JsonConvert.DeserializeObject<GetRoomResponse>(response); GetRoomResponse getRoomResponse = new JavaScriptSerializer().Deserialize <GetRoomResponse>(response); ListBoxItem listBoxItem = new ListBoxItem(); foreach (string room in getRoomResponse.rooms) { RoomData tempRoomData = new JavaScriptSerializer().Deserialize <RoomData>(room); listBoxItem.Content = tempRoomData.name; Room_list.Items.Add(listBoxItem); room_detailes.Add(tempRoomData); } }
private void SignOutClick(object sender, RoutedEventArgs e) { string request = Constants.SIGNOUT_ID.ToString() + "0"; string response = helper.SendAndRecive(request); LogoutResponse loginResponse = new JavaScriptSerializer().Deserialize <LogoutResponse>(response); MainWindow mainWindow = new MainWindow(); mainWindow.Show(); this.Close(); }
public MyProfileWindow() { InitializeComponent(); string request = Constants.GET_HIGHSCORES_ID.ToString() + "0"; string response = helper.SendAndRecive(request); MessageBox.Show(response); HighscoreResponse highscoreResponse = new JavaScriptSerializer().Deserialize <HighscoreResponse>(response); add_details(new Thickness(360, 120, 0, 0), highscoreResponse.num_games.ToString()); add_details(new Thickness(360, 200, 0, 0), highscoreResponse.right_answers.ToString()); add_details(new Thickness(360, 280, 0, 0), highscoreResponse.worng_answers.ToString()); add_details(new Thickness(360, 360, 0, 0), highscoreResponse.averag_time_for_answer.ToString()); }