Ejemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="proxy"></param>
        /// <param name="callbackID"></param>
        public QuiddlerUI(IQuiddlerService proxy, int callbackID)
        {
            InitializeComponent();
            try
            {
                // Initialize members
                buttons = new List<ToggleButton>();

                // Load the proxy and callbackID from the login window
                remoteProxy = proxy;
                clientCallbackId = callbackID;

                // Group buttons into an aggregrate object
                groupButtons();

                // Load sounds
                sounds = new AudioDeck();
                sounds.Add("user_joined", "{path_here}");
                sounds.Add("user_left", "{path_here}");
                sounds.Add("user_scored", "{path_here}");
                sounds.Add("user_quit", "{path_here}");
                sounds.Add("game_over", "{path_here}");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        private void btnJoinNetworked_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Clear previous status
                UpdateStatus("");

                if (txtServAddr.Text != "")
                {
                    // Valid IP Address
                    if (Regex.IsMatch(txtServAddr.Text, ipCheck))
                    {
                        if (txtUserName.Text != "")
                        {
                            // Configure server endpoint
                            ConfigureEndpoint(txtServAddr.Text, txtServPort.Text);

                            // Indicate waiting condition
                            UpdateStatus("Connecting to " + remoteFactory.Endpoint.Address.ToString() + "...");

                            // Create an instance of my UpdateProgressarDelegate
                            UpdateProgBarDelegate theProgBarDelegate = new UpdateProgBarDelegate(progressBar1.SetValue);

                            // Activate a remote QuiddlerService object
                            remoteProxy = remoteFactory.CreateChannel();

                            // Animate progress bar
                            AnimateProgressBar(theProgBarDelegate, 2000, 0, 0);

                            // Username already taken
                            if (remoteProxy.usernameExists(txtUserName.Text))
                            {
                                UpdateStatus("That username is already taken");
                            }
                            else
                            {
                                // Create a new client instance
                                Tuple<int, string> result = remoteProxy.Register_client();
                                if (result.Item1 != -1)
                                {
                                    widQuiddler = new QuiddlerUI(remoteProxy, result.Item1);
                                    widQuiddler.join(txtUserName.Text);
                                    widQuiddler.lblWelcome2.Content = txtUserName.Text;
                                    widQuiddler.Show();
                                    this.Close();
                                }
                                else
                                {
                                    UpdateStatus(result.Item2);
                                }
                            }

                            // Reset progress bar
                            progressBar1.Value = 0;
                        }
                        else
                        {
                            UpdateStatus("Please enter a valid username");
                        }
                    }
                    else
                    {
                        UpdateStatus("Invalid address, please try again");
                    }
                }
                else
                {
                    UpdateStatus("Please enter a valid IP address");
                }
            }
            catch (Exception ex)
            {
                UpdateStatus(ex.Message);
            }
        }