示例#1
0
        private void btnReplay_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".sgs"; // Default file extension
            dlg.Filter = "Replay File (.sgs)|*.sgs|All Files (*.*)|*.*"; // Filter files by extension
            bool? result = dlg.ShowDialog();
            if (result != true) return;

            string fileName = dlg.FileName;

            Client client;
            int mainSeat = 0;
            MainGame game = null;
            try
            {
                client = new Client();
                client.Start(true, File.Open(fileName, FileMode.Open));
                mainSeat = (int)client.Receive();
                client.SelfId = mainSeat;
                game = new MainGame();
                game.MainSeat = mainSeat;
                game.NetworkClient = client;
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to open replay file.");
                return;
            }
            if (game != null)
            {
                this.NavigationService.Navigate(game);
            }
        }
示例#2
0
        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            if (loginTab.SelectedIndex == 0)
            {
                Client client;
                int mainSeat = 0;

                client = new Client();
                string addr = tab0HostName.Text;
                string[] args = addr.Split(':');
                client.IpString = args[0];
                if (args.Length >= 2)
                {
                    client.PortNumber = int.Parse(args[1]);
                }
                else
                {
                    client.PortNumber = 12345;
                }
                busyIndicator.BusyContent = Resources["Busy.ConnectServer"];
                busyIndicator.IsBusy = true;

                //client.Start(isReplay, FileStream = file.open(...))
                BackgroundWorker worker = new BackgroundWorker();

                worker.DoWork += (o, ea) =>
                {
                    try
                    {
                        ea.Result = false;
                        client.Start();
                        mainSeat = (int)client.Receive();
                        client.SelfId = mainSeat;
                        ea.Result = true;
                    }
                    catch (Exception)
                    {
                    }
                };

                worker.RunWorkerCompleted += (o, ea) =>
                {
                    busyIndicator.IsBusy = false;
                    if ((bool)ea.Result)
                    {
                        MainGame game = new MainGame();
                        game.MainSeat = mainSeat;
                        game.NetworkClient = client;
                        this.NavigationService.Navigate(game);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Failed to create connection");
                    }
                };

                worker.RunWorkerAsync();
            }
        }