Example #1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (IsBluetoothGame())
            {
                var peer = peerList.SelectedItem as PeerAppInfo;
                Bluetooth.ConnectToPeer(peer.PeerInfo);
                Bluetooth.CommandRecieved += (byte command) => {
                    switch (command)
                    {
                    case BluetoothCommands.AcceptInvite:
                        MessageBox.Show("accept");
                        break;

                    case BluetoothCommands.DiscardInvite:
                        MessageBox.Show("discard");
                        break;
                    }
                };
            }
            else
            {
                NavigationService.Navigate(new Uri(String.Format("/GamePage.xaml?FieldSize={0}&FirstMove={1}",
                                                                 GetFieldSize(), GetFirstMove()), UriKind.Relative));
            }
        }
Example #2
0
 private void ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     try {
         Dispatcher.BeginInvoke(() => {
             Bluetooth.ConnectToPeer(args.PeerInformation);
             rivalName  = args.PeerInformation.DisplayName;
             var result = MessageBox.Show(String.Format("Пользователь {0} предлагает вам игру. Принять приглашение?",
                                                        rivalName), "Приглашение", MessageBoxButton.OKCancel);
             if (result == MessageBoxResult.OK)
             {
                 Bluetooth.SendCommand(BluetoothCommands.AcceptInvite);
             }
             else
             {
                 Bluetooth.SendCommand(BluetoothCommands.DiscardInvite);
                 Bluetooth.Disconnect();
             }
         });
     }
     catch (Exception ex) {
         MessageBox.Show(ex.Message);
     }
 }