/// <summary> /// Validates inputs and starts the game. /// </summary> private void ValidateInputs() { try { playerName = NameTextBox.Text; if (AgeTextBox.Text != "") { playerAge = Int32.Parse(AgeTextBox.Text); } ///Store Game Type if (AddRadioBtn.IsChecked == true) { gameType = clsGame.GameType.Addition; } else if (SubtractRadioBtn.IsChecked == true) { gameType = clsGame.GameType.Subtraction; } else if (MultiplyRadioBtn.IsChecked == true) { gameType = clsGame.GameType.Multiplication; } else { gameType = clsGame.GameType.Division; } ///Display red error label for errors if (playerAge > 10 || playerAge < 3) { ErrorLabel.Visibility = Visibility.Visible; ErrorLabel.Content = "Error: Age must be between 3 and 10."; } else if (playerName == "") { ErrorLabel.Content = "Error: Please enter your name."; } ///Move to next Screen if (playerName != "" && playerAge >= 3 && playerAge <= 10) { player = new clsUser(playerName, playerAge); game = new clsGame(gameType); GameWindow objGameWindow = new GameWindow(game, player, this); this.Hide(); objGameWindow.ShowDialog(); this.Show(); } } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
/// <summary> /// Initialize Game Window /// </summary> /// <param name="game"></param> /// <param name="user"></param> public GameWindow(clsGame game, clsUser user, Window objGameWindow) { ///Exception handling for the normal method try { InitializeComponent(); this.game = game; this.player = user; QuestionLabel.Content = this.game.questionToString(0); /// Set up the timer MyTimer = new DispatcherTimer(); MyTimer.Interval = TimeSpan.FromSeconds(1); MyTimer.Tick += MyTimer_Tick1; } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }