private void UpdateWithServerData(SignalREventArgs e) { App.Current.AppUser = e.UserUpdate; //Upload Games App.Current.AllGames = e.CustomGameList; App.Current.OppUsers = e.CustomAvailableOpponents; //App.Current.SignalRHub.SignalRServerNotification -= new SignalRServerHandler(SignalRHub_SignalRServerNotification); Debug.WriteLine("GameSettings: remove listener in UpdateWithServerData"); //NavigationService.Navigate(new Uri("/HubPage1.xaml", UriKind.RelativeOrAbsolute)); }
protected async void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e) { await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { //...has already started //upDate Game Object Start time //start timer //e.InGameActionMessageEvent(state) App.Current.CurrentGame = e.CustomGameObject; LivesLeftBlock.Text = "Lives Left: " + App.Current.CurrentGame.MaxHits; //StateBlock.Text = "State: " + App.Current.CurrentGame.GameState; //feed back from Ready if (e.CustomGameObject.GameStatus < 4) //opp not ready { // waitingBlock.Text = "Waiting for Opponent..."; } else { //Make visible in Visible /* image.Visibility = Windows.UI.Xaml.Visibility.Collapsed; image2.Visibility = Windows.UI.Xaml.Visibility.Collapsed; waitingBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed; */ //Call Start if you were the last one ready } if (e.InGameActionMessageEvent.Action == "end") { //Triger End event if (App.Current.CurrentGame != null) { if (e.CustomGameObject.SpheroPlayer.UserName == App.Current.AppUser.UserName) { if (e.CustomGameObject.Winner.UserName == App.Current.AppUser.UserName) { App.Current.AppUser.GWAS++; } else { App.Current.AppUser.GLAS++; } } App.Current.CurrentGame = null; EndGame(e.CustomGameObject); } } else { switch (e.CustomGameObject.GameState) { //main state of game case 0: if (e.InGameActionMessageEvent.Action == "start") { //STOP HERE!!!!!!!! //if I'm a sphero display Warning if (App.Current.AppUser.UserId == e.CustomGameObject.DronePlayer.UserId) { Message_Block.Text = "One minute before Targeting systems are active."; } if (App.Current.AppUser.UserId == e.CustomGameObject.SpheroPlayer.UserId) { Message_Block.Text = "You have One minute to hide!"; } } if (e.InGameActionMessageEvent.Action == "hit") { _hits = e.InGameActionMessageEvent.Hits; if (App.Current.AppUser.UserId == e.CustomGameObject.DronePlayer.UserId) { Message_Block.Text = "Hit Successful"; } if (App.Current.AppUser.UserId == e.CustomGameObject.SpheroPlayer.UserId) { Message_Block.Text = "You've been hit!"; int x = e.CustomGameObject.MaxHits--; LivesLeftBlock.Text = "Lives left: " + x.ToString(); } } if (e.InGameActionMessageEvent.Action == "lost") { if (App.Current.AppUser.UserId == e.CustomGameObject.DronePlayer.UserId) { Message_Block.Text = "Lost Target!"; } if (App.Current.AppUser.UserId == e.CustomGameObject.SpheroPlayer.UserId) { Message_Block.Text = "Evaded the enemy"; } } //Actions - update GameObject - start Time, targeted, end break; //targeted state case 1: if (e.InGameActionMessageEvent.Action == "targeted") { //if I'm a sphero display Warning if (App.Current.AppUser.UserId == e.CustomGameObject.DronePlayer.UserId) { Message_Block.Text = "Locked on Target"; } if (App.Current.AppUser.UserId == e.CustomGameObject.SpheroPlayer.UserId) { Message_Block.Text = "TARGETED!"; } } //Actions - fire, end(time), end(hits), lost break; //End State (show Winner message) case 2: //Current.Game = null break; default: break; } } }); }
/* private void CreateGameButton_Clicked(object sender, RoutedEventArgs e) { //send call to create //wait till server resonds //flag do you wnat to join now? //if no update user on this page then transfer to HUB //if yes go to Lobby send lobby shit string s; if (_maxTime < 0 || _maxHits < 0 || App.Current.OppUserTest == null) { if (_maxHits < 0) { s = "Error: You need to choose how many lives Sphero Player will have."; GameError(s); } else { if (opponent.UserName == null || App.Current.OppUserTest == null) { s = "Error: You need to select an opponent"; GameError(s); } else { if (_maxTime <0) { s = "Error: You need to choose how long the game will last."; GameError(s); } } } } else { Game ugame = new Game(); ugame.DateCreated = DateTime.Now; ugame.OpponentName = App.Current.OppUserTest.UserName; //your good ugame.MaxTime = _maxTime; ugame.MaxHits = _maxHits; ugame.GameStatus = 0; ugame.GameId = App.Current.AppUser.UserId + "game"; App.Current.CurrentGame = ugame; //Frame.Navigate(typeof(HubPage)); } }*/ protected void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e) { Deployment.Current.Dispatcher.BeginInvoke(() => { //Debug.WriteLine("SEND, - SIMPLE CHAT WORKS- "+e.ChatMessageFromServer); if (e.CustomServerMessage != null) { switch (e.CustomServerMessage.Command) { //Login case 0: //Update Game List if (e.CustomServerMessage.Action == "login") { if (e.UserUpdate.UserName != App.Current.AppUser.UserName) { e.CustomAvailableOpponents.Add(e.UserUpdate); } else { UpdateWithServerData(e); } } break; case 1: if (e.CustomServerMessage.Action == "update") { if (e.UserUpdate.UserName == App.Current.AppUser.UserName) { App.Current.AppUser = e.UserUpdate; App.Current.AllGames = e.CustomGameList; App.Current.OppUsers = e.CustomAvailableOpponents; if (!iscreatingagame) { Debug.WriteLine("Game Settings: Update " + e.CustomServerMessage.Message); NavigationService.Navigate(new Uri("/HubPage1.xaml", UriKind.RelativeOrAbsolute)); } } } break; case 2: if (e.CustomServerMessage.Action == "created") { if (App.Current.AppUser.UserName == e.CustomGameObject.CreatorName) { Debug.WriteLine("SettingsPage created game listener called."); //Add game to users game list App.Current.AllGames.Add(e.CustomGameObject); App.Current.CurrentGame = e.CustomGameObject; Debug.WriteLine("Created A Game " + e.CustomServerMessage.Message); //Frame.Navigate(typeof(LobbyPage)); //Update User information //Ask if they want to join ServerMessage sm = new ServerMessage(0, "update", "created a game"); App.Current.SignalRHub.UserUpdate(App.Current.AppUser, sm); Debug.WriteLine("SettingsPage: Starting OpenJoinMessageDIalog"); //OpenJoinMessageDialog(); Debug.WriteLine("SettingsPage: COmpleted Dialog"); } } break; default: break; } } }); }
public void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e) { //await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync ( CoreDispatcherPriority.High, () => //{ if (e.CustomServerMessage != null) { //App.Current.CurrentGame = e.CustomGameObject; switch (e.CustomServerMessage.Command) { //Login case 0: /* //Update Game List if (e.CustomServerMessage.Action == "login") { App.Current.AppUser = e.UserUpdate; //Upload Games App.Current.AllGames = e.CustomGameList; Debug.WriteLine(e.UserUpdate.UserName + " " + e.CustomServerMessage.Message); }*/ break; case 1: Debug.WriteLine(e.CustomServerMessage.Action + "MESSAGE- " + e.CustomServerMessage.Message); break; case 2: /* if (e.CustomServerMessage.Action == "created") { //Add game to users game list App.Current.AllGames.Add(e.CustomGameObject); Debug.WriteLine("Created A Game " + e.ChatMessageFromServer); Frame.Navigate(typeof(LobbyPage)); //Ask if they want to join //OpenMessageDialog("join",e.CustomGameObject); }*/ break; case 3: Debug.WriteLine("LobbyPage: Action " + e.CustomServerMessage.Action + " " +e.CustomServerMessage.Message); if (e.CustomServerMessage.Action == "join") { //This means you are the first , or second to join // Message: User has joined the Game // Message: User has left Game Lobby Debug.WriteLine("LobbyPage: JOIN "+e.CustomServerMessage.Message); //CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Deployment.Current.Dispatcher.BeginInvoke(() => { chatDialog.Text += "\r\n" + e.CustomServerMessage.Message; }); } if (e.CustomServerMessage.Action == "ready") { //if you get here then you were not the one to hit ready Debug.WriteLine("LobbyPage: REady other opp is ready " + e.CustomServerMessage.Message); chatDialog.Text += "\r\n" + e.CustomServerMessage.Message; /* if (e.UserUpdate.UserName == App.Current.AppUser.UserName && e.CustomGameObject.GameStatus<3) { chatDialog.Text += "\r\n" + e.CustomServerMessage.Message + " Waiting for opponent..."; md = e.CustomServerMessage.Message + " Waiting for opponent..."; } else { chatDialog.Text += "\r\n" + e.CustomServerMessage.Message; md = e.CustomServerMessage.Message; } if (e.CustomGameObject.GameStatus > 2) { StartingGame(App.Current.CurrentGame, e.UserUpdate); } */ } /* if (e.CustomServerMessage.Action == "start") { chatDialog.Text += "\r\n" + e.CustomServerMessage.Message; //chatDialog.Text += "\r\n" + "Game now starting..."; //if (e.UserUpdate.UserName == App.Current.AppUser.UserName) //{ StartGame(App.Current.CurrentGame,e.UserUpdate); //} } * */ break; case 4: Debug.WriteLine("LobbyPage: Case4"); ChangeToGamePage(); break; //start command default: break; } } // Add to local ChatRoom. //chatDialog.Text += "\r\n" + e.ChatMessageFromServer; //}); }
private void UpdateWithServerData(SignalREventArgs e) { App.Current.AppUser = e.UserUpdate; //Upload Games App.Current.AllGames = e.CustomGameList; App.Current.OppUsers = e.CustomAvailableOpponents; App.Current.SignalRHub.SignalRServerNotification -= new SignalRServerHandler(SignalRHub_SignalRServerNotification); }
protected void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e) { Deployment.Current.Dispatcher.BeginInvoke( () => //await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync ( CoreDispatcherPriority.High, () => { //Debug.WriteLine("SEND, - SIMPLE CHAT WORKS- "+e.ChatMessageFromServer); if (e.CustomServerMessage != null) { switch (e.CustomServerMessage.Command) { //Login case 0: //Update Game List if (e.CustomServerMessage.Action == "login") { UpdateWithServerData(e); //LoggedInMessageBox(); NavigationService.Navigate(new Uri("/HubPage1.xaml", UriKind.Relative)); } break; case 1: if (e.CustomServerMessage.Action == "update") { UpdateWithServerData(e); //LoggedInMessageBox(); NavigationService.Navigate(new Uri("/HubPage1.xaml", UriKind.Relative)); } break; default: break; } } }); }
protected void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e) { /* await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => */ if (e.CustomServerMessage != null) { switch (e.CustomServerMessage.Command) { //Login case 0: //Update Game List if (e.CustomServerMessage.Action == "login") { if (e.UserUpdate.UserName != App.Current.AppUser.UserName) { App.Current.OppUsers.Add(e.UserUpdate); } else { UpdateWithServerData(e); } // Frame.Navigate(typeof(HubPage)); } break; case 1: if (e.CustomServerMessage.Action == "update") { if (App.Current.AppUser.UserName == e.UserUpdate.UserName) { UpdateWithServerData(e); } } break; case 2: if (e.CustomServerMessage.Action == "created") { if (e.CustomGameObject.OpponentName == App.Current.AppUser.UserName) { Debug.WriteLine("HubPage: CREATED "+e.CustomServerMessage.Message); App.Current.AllGames.Add(e.CustomGameObject); SpheroGameListBox.Items.Clear(); SpheroGameListBox.ItemsSource = App.Current.AllGames; //Someone else created the game notify user to call on navigated to } else { //OpenMessageDialog(e.CustomGameObject); } } break; case 3: Debug.WriteLine("Hub Page: Join happend on this page instead of Lobby"); break; default: break; } } // }); }