/// <summary> /// Stops the game play if the game is over. Executes after GetGameState() on the web service completes. /// </summary> /// <param name="sender">The calling object</param> /// <param name="e">Any arguments passed from the web service. Contains the updated score.</param> private void WebService_GetGameStateCompleted(object sender, GetGameStateCompletedEventArgs e) { if (e.Result) { //if game is active, set local variable to true. //This variable is used by the KeyDown event in the UserControl_KeyDown() method to stop the player moving shapes if the game is over gameInProgress = true; } else { //if false... gameInProgress = false; //stop the player moving shapes if (!scoreSubmitted) { webService.SubmitScoreAsync(); //submit the final score to the web service scoreSubmitted = true; } timer.Stop(); //stop the timer lblName.Content = "Game Over"; //replace the players name with 'Game Over' } }
/// <summary> /// Handler called after receiving the current game state from the server. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void proxy_GetGameStateCompleted(object sender, GetGameStateCompletedEventArgs e) { if (e.Error != null && ServiceError != null) { // Raise an error notification ServiceError(this, new ExceptionEventArgs() { Error = e.Error }); } else if (e.Result != null) { MemoryStream memoryStream = new MemoryStream(e.Result); Message message = ReadServerMessage(memoryStream); NewGameState((message.Body as GameState)); } else if (GameUnavailable != null) { GameUnavailable(this, EventArgs.Empty); } }