public void Play(object sender, GestureEventArgs gestureEventArgs) { var cup = ((CupControl)sender).DataContext as CupVM; var currentGameState = Game.State; if (!Game.Play(cup)) { return; } SystemTray.ProgressIndicator.IsVisible = true; Context.UpdateGame(Player.Name, Game.ToGame(), game => Dispatcher.BeginInvoke(() => { SystemTray.ProgressIndicator.IsVisible = false; switch (Game.State) { case GameState.Finished: var winner = Game.Winner; var score = Game.Score(winner).Stones; if (winner == Player) { MessageBox.Show("Congratulations, you won! You have earned " + score + " points."); Context.ScorePlayer(winner.Name, score, player => Dispatcher.BeginInvoke(NavigationService.GoBack) , () => { }); } else { MessageBox.Show("Sorry, you lost."); Context.ScorePlayer(winner.Name, score, player => Dispatcher.BeginInvoke(NavigationService.GoBack) , () => { }); } break; case GameState.Client: if (currentGameState != GameState.Client) { _nsc.NotifyAsync(Player.Name, Game.Client.Name, Game.Id); } else { CupControl.AnimationDelayIndex = 0; } break; case GameState.Host: if (currentGameState != GameState.Host) { _nsc.NotifyAsync(Player.Name, Game.Host.Name, Game.Id); } else { CupControl.AnimationDelayIndex = 0; } break; } }), () => Dispatcher.BeginInvoke(() => { SystemTray.ProgressIndicator.IsVisible = false; MessageBox.Show("Failed to register play. Try again."); }) ); }