Exemplo n.º 1
0
        private void switchToNextWindow()
        {
            ChatReadyWindow _ChatReadyWindow = new ChatReadyWindow();

            App.Current.MainWindow = _ChatReadyWindow;
            _ChatReadyWindow.Show();
            this.Close();
        }
Exemplo n.º 2
0
 private async void Connect_btn_Click(object sender, RoutedEventArgs e)
 {
     await Task.Run(() =>
     {
         disableGraphicsAndWait();
         bool invalidRoomID = false;
         //Validiate Room ID
         this.Dispatcher.Invoke((Action)(() =>
         {
             try
             {
                 globalVars.roomId = Convert.ToInt32(RoomId_txt.Text);
             }
             catch (Exception)
             {
                 invalidRoomID = true;
                 globalVars.roomId = 0;
                 MessageBox.Show("Invalid Room ID!", "Invalid Info.",
                                 MessageBoxButton.OK, MessageBoxImage.Error);
                 resetGraphics();
             }
         }));
         if (invalidRoomID)
         {
             return;                //Don't Make Progress just return
         }
         //Get The Room Data By ID
         gameRoom gr = new gameRoom(globalVars.roomId);
         if (gr.id == 0) //Room Not Found!
         {
             globalVars.roomId = 0;
             MessageBox.Show("Room Not Found!", "Invalid Info.",
                             MessageBoxButton.OK, MessageBoxImage.Error);
             resetGraphics();
             return;
         }
         else
         {
             //Trying To Establish a connection to the host:
             try
             {
                 string MemoryGameServiceHostUri = "http://" + gr.host_IP + ":8888/MemoryGameService/MemoryGameService/";
                 EndpointAddress MemoryGameServiceEndpointAddress = new EndpointAddress(MemoryGameServiceHostUri);
                 BasicHttpBinding _BasicHttpBinding = new BasicHttpBinding();
                 ChannelFactory <IMemoryGameService> _ChannelFactory =
                     new ChannelFactory <IMemoryGameService>(_BasicHttpBinding, MemoryGameServiceEndpointAddress);
                 globalVars.proxy = _ChannelFactory.CreateChannel();
             }
             catch (Exception ex)
             {
                 globalVars.roomId = 0;
                 MessageBox.Show(ex.Message, "Cannot Establish a Connection.",
                                 MessageBoxButton.OK, MessageBoxImage.Error);
                 resetGraphics();
                 return;
             }
             //Trying To Join The Game Room:
             bool isJoined = false;
             try
             {
                 isJoined = globalVars.proxy.joinRoom(globalVars.roomId,
                                                      globalVars.player.id, globalVars.userIp);
             }
             catch (Exception ex)
             {
                 globalVars.roomId = 0;
                 MessageBox.Show(ex.Message, "Connection Lost :(",
                                 MessageBoxButton.OK, MessageBoxImage.Error);
                 resetGraphics();
                 return;
             }
             //If Joined Successfully -> Switch To The Next Window:
             if (isJoined)
             {
                 Application.Current.Dispatcher.Invoke((Action) delegate
                 {
                     //switch to next window
                     ChatReadyWindow _ChatReadyWindow = new ChatReadyWindow();
                     App.Current.MainWindow           = _ChatReadyWindow;
                     _ChatReadyWindow.Show();
                     this.Close();
                 });
             }
             else
             {
                 globalVars.roomId = 0;
                 MessageBox.Show("Sorry, No Late Join :(", "Cannot Join This Room.",
                                 MessageBoxButton.OK, MessageBoxImage.Error);
                 resetGraphics();
                 return;
             }
         }
     });
 }