public MainWindow() { InitializeComponent(); game = new clsGame(); wndGameForm = new wndGameForm(); Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose; rdoAdd.IsChecked = true; txtName.Focus(); }
/// <summary> /// Checks to see if the game can start, and then starts the game if so. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPlay_Click(object sender, RoutedEventArgs e) { try { SoundPlayer simpleSound = new SoundPlayer("Happy-Confirmation.wav"); string name = txtName.Text; int age; if (Int32.TryParse(txtAge.Text, out age) && name != "" && age > 3 && age < 10) { User = new clsUser(name, age); simpleSound.Play(); wndGameForm = new wndGameForm(); wndGameForm.User = User; wndGameForm.game = game; lblError.Content = ""; //Hide the menu this.Hide(); //Show the game form wndGameForm.ShowDialog(); //Show the main form this.Show(); } else if (name == "") { lblError.Content = "Please enter a name"; } else if (age < 3 || age > 10) { lblError.Content = "The age must be between 3 and 10"; } else { lblError.Content = "Please enter a valid age"; } } catch (Exception ex) { //This is the top level method so we want to handle the exception HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }