/// <summary> /// Is called when the button for direct connection is clicked /// </summary> /// <param name="sender">The clicked button</param> /// <param name="e">The event arguments</param> private void btnDirect_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrWhiteSpace(tbPartnerJID.Text)) { MessageBox.Show("Please enter the Jabber-ID of your game partner.", "Error", MessageBoxButton.OK); } else { try { Match newMatch = new Match("1337", AppCache.XmppManager.OwnID, new JID(tbPartnerJID.Text)); StartGame(newMatch); } catch (Exception ex) { MessageBox.Show("Please enter a valid Jabber-ID of your game partner.", "Error", MessageBoxButton.OK); } } }
/// <summary> /// Connects to the Jabber server /// </summary> private void HandleConnect() { if (cbAnonymous.IsChecked == true) { // This is for debugging. Allows to start a match without beeing logged in //MessageBox.Show("Not implemented!"); AppCache.XmppManager = new XMPPManager(tbJID.Text, tbPwd.Password, this); Match m = new Match("123", new JID(tbJID.Text), new JID("*****@*****.**")); StartGame(m); } else { if (String.IsNullOrEmpty(tbJID.Text) || String.IsNullOrEmpty(tbPwd.Password)) { MessageBox.Show("Please insert your Jabber-ID and Password!", "Error", MessageBoxButton.OK); } else { AppCache.XmppManager = new XMPPManager(tbJID.Text, tbPwd.Password, this); AppCache.XmppManager.Client.Connect(); } } }
/// <summary> /// References AppCache.CurrentMatch to the given match and navigates to the XNA part of the game /// </summary> /// <param name="newMatch">The new match</param> public void StartGame(Match newMatch) { AppCache.CurrentMatch = newMatch; NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative)); }
void XmppClient_OnXMLReceived(XMPPClient client, string strXML) { BattleshipMessage bMessage = XMLManager.GetBattleshipMessage(strXML); if (bMessage != null) { if (bMessage is QueuingMessage) { Match m = null; System.Windows.Media.SolidColorBrush brush = null; QueuingMessage qMessage = (QueuingMessage)bMessage; String s = ""; if (qMessage.Action== Enum.QueueingAction.success) { s = "Searching partner. Please wait..."; this.queueID = qMessage.ID; brush = AppCache.cYellow; } else if (qMessage.Action == Enum.QueueingAction.ping) { OnIncomingQueuingPing(new MessageEventArgs(qMessage)); } else if (qMessage.Action == Enum.QueueingAction.assign) { if (QueuingProcess) { QueuingProcess = false; Matchmaker.Assigned(this, qMessage.JID, qMessage.MatchID); m = new Match(qMessage.MatchID, this.OwnID, qMessage.JID); } s = "Assigned with partner!"; brush = AppCache.cGreen; } mainPage.Dispatcher.BeginInvoke(delegate { if (!String.IsNullOrEmpty(s)) { mainPage.lblSearchState.Text = s; } if (m != null) mainPage.StartGame(m); if (brush != null) mainPage.ledWaitingState.Fill = brush; }); } else if (bMessage is MatchMessage) { MatchMessage mMessage = (MatchMessage)bMessage; switch (mMessage.Action) { case Enum.MatchAction.Diceroll: if (AppCache.CurrentMatch != null) { this.OnIncomingDiceroll(new RollingDiceEventArgs(mMessage.Dice)); } break; case Enum.MatchAction.Shot: if (AppCache.CurrentMatch != null) { this.OnIncomingShot(new ShootEventArgs(mMessage.X, mMessage.Y)); } break; case Enum.MatchAction.Shotresult: if (AppCache.CurrentMatch != null) { if (mMessage.ShipInfo != null) { this.OnIncomingShotResult(new ShootEventArgs(mMessage.X, mMessage.Y, mMessage.Result, mMessage.ShipInfo)); } else { this.OnIncomingShotResult(new ShootEventArgs(mMessage.X, mMessage.Y, mMessage.Result)); } } break; case Enum.MatchAction.Ping: if (AppCache.CurrentMatch != null) { this.OnIncomingMatchPing(new MessageEventArgs(mMessage)); } break; case Enum.MatchAction.Gamestate: if (AppCache.CurrentMatch != null) { this.OnIncomingGamestate(new MessageEventArgs(mMessage)); } break; } } } }