public Window_HighScores() { WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; InitializeComponent(); CheckIfAudioMutedOrNot(); Top10Only.Show(this.lblRankHeaderAndContent, this.lblDateHeaderAndContent, this.lblScoreHeaderAndContent); }
private void GameOver() { lblMissed.Content = "Missed: " + missedBalloons; isGameActive = false; timerGame.Stop(); Top10Only.CheckResultInTop10Only(dateToday, Convert.ToInt32(score)); inGameAudio.StopPlaying(); if (Window_Introduction.isAudioOn == true) { gameOverAudio.Play(false); } MessageBoxResult result = MessageBox.Show("Your Score: " + score + Environment.NewLine + "Missed: " + missedBalloons + Environment.NewLine + Environment.NewLine + "Do you want to play again?", "GAME OVER", MessageBoxButton.YesNo, MessageBoxImage.Information); if (result == MessageBoxResult.Yes) { gameOverAudio.StopPlaying(); StartGame(); } else if (result == MessageBoxResult.No) { gameOverAudio.StopPlaying(); Window_Introduction nextWindow = new Window_Introduction(); this.Visibility = Visibility.Collapsed; nextWindow.ShowDialog(); } }
public static void CheckResultInTop10Only(string param_Date, int param_Score) { if (Top10Only.CheckingIfScoreIsAcceptable(param_Score)) { Top10OnlyEntry entry = new Top10OnlyEntry(); entry.Date = param_Date; entry.Score = param_Score; Top10Only.EnterTop10Only(entry); } }
private void timerGame_Tick(object sender, EventArgs e) { dateToday = DateTime.Now.ToString("MM/dd/yyyy"); lblScore.Content = "Your Score: " + Top10Only.AddingCommasInScore(Convert.ToString(score)); lblMissed.Content = "Missed: " + missedBalloons; // Decrease the value of field called intervals by 10. intervals -= 10; // If the value of field called intervals is less than 1. if (intervals < 1) { // Paints the area of an image using the class called ImageBrush. ImageBrush balloonImage = new ImageBrush(); // Increment the field called balloonsColors by 1. balloonsColors += 1; // If the value of field called balloonsColors is greater than 5. if (balloonsColors > 5) { // Re assign the value of field called balloonsColors. balloonsColors = 1; } switch (balloonsColors) { case 1: balloonImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/balloon1.png")); break; case 2: balloonImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/balloon2.png")); break; case 3: balloonImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/balloon3.png")); break; case 4: balloonImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/balloon4.png")); break; case 5: balloonImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/balloon5.png")); break; } // Draw a rectangle using the class called Rectangle. Rectangle newBalloon = new Rectangle { Tag = "balloon", Height = 70, Width = 50, Fill = balloonImage }; // Set the location in the Canvas. Canvas.SetLeft(newBalloon, randomNumber.Next(50, 400)); Canvas.SetTop(newBalloon, 600); // Add the new balloons in the Canvas. MyCanvas.Children.Add(newBalloon); // Re assign the value of the field called intervals. intervals = randomNumber.Next(90, 150); } // Using the foreach loop to control every balloons. foreach (var x in MyCanvas.Children.OfType <Rectangle>()) { // Check if there are Rectangle that have a tag name of "balloon". if ((string)x.Tag == "balloon") { horizontalAxis = randomNumber.Next(-5, 5); Canvas.SetTop(x, Canvas.GetTop(x) - speed); Canvas.SetLeft(x, Canvas.GetLeft(x) - (horizontalAxis * -1)); } // If the balloon exceeds the height. if (Canvas.GetTop(x) < 20) { // Add that balloon in the list of rectangle. itemRemover.Add(x); CheckIfAudioMutedOrNot("missed_balloon.wav"); missedBalloons += 1; } } // Using the foreach loop to control every balloons. foreach (Rectangle y in itemRemover) { // Remove that balloons in the Canvas. MyCanvas.Children.Remove(y); } // If the field called missedBalloons have the value of greater than 9. if (missedBalloons > 9) { // Invoke this user defined function called GameOver(). GameOver(); } // If the field called score have the value of greater than 10. if (score > 10) { speed = 5; // Re assign the value of field called speed. } }