Ejemplo n.º 1
0
        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
            {
            }
        }
Ejemplo n.º 2
0
        private void JoinClick(object sender, RoutedEventArgs e)
        {
            string name = (Room_list.SelectedItem as ListBoxItem).Content.ToString();

            foreach (RoomData room_data in room_detailes)
            {
                if (room_data.name == name)
                {
                    JoinRoomRequest  joinRoomRequest  = new JoinRoomRequest(room_data.get_id());
                    var              json             = new JavaScriptSerializer().Serialize(joinRoomRequest);
                    string           request          = Constants.JOIN_ROOM_ID.ToString() + json.Length.ToString() + json;
                    string           response         = helper.SendAndRecive(request);
                    JoinRoomResponse joinRoomResponse = new JavaScriptSerializer().Deserialize <JoinRoomResponse>(response);
                    if (joinRoomResponse.status == Constants.SUCCESS_STATUS)
                    {
                        BeforeGameWindow beforeGameWindow = new BeforeGameWindow(name, false);
                        beforeGameWindow.Show();
                        this.Close();
                    }
                }
            }
        }