Ejemplo n.º 1
0
        /// <summary>
        /// Validates users input and then sets attributes accordingly
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdPlayGame_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtboxName.Text))
            {
                sndBump.Play();
                lblUserDataError.Content = "Please enter your name";
            }
            else if (String.IsNullOrWhiteSpace(txtboxAge.Text))
            {
                sndBump.Play();
                lblUserDataError.Content = "Please enter your age";
            }
            else if (!ValidateInput.isWithinAgeRange(txtboxAge.Text))
            {
                sndBump.Play();
                lblUserDataError.Content = "Please enter an age between 3 - 10";
            }
            else if (radioAdd.IsChecked == false && radioSubtract.IsChecked == false && radioMultiply.IsChecked == false && radioDivide.IsChecked == false)
            {
                sndBump.Play();
                lblUserDataError.Content = "Please select an operation (+ , - , x , or /)";
            }
            //everything is good
            else
            {
                //sets users age
                clsUser.age = Convert.ToInt32(txtboxAge.Text);

                //sets users name
                clsUser.name = Convert.ToString(txtboxName.Text);

                //creates new game with users name and age
                wndGameForm = new wndGame(clsUser.name, clsUser.age);

                //sets the game type
                CheckOperation();

                //play "ZoomIn" mario sound
                sndZoomIn.Play();

                //Hide the menu
                this.Hide();

                //Hide the Game form so we can ShowDialog(); ??
                wndGameForm.Hide();

                //Show the Game form
                wndGameForm.ShowDialog();
            }
        }
        public wndMathMenu()
        {
            InitializeComponent();

            //MAKE SURE TO INCLUDE THIS LINE OR THE APPLICATION WILL NOT CLOSE
            //BECAUSE THE WINDOWS ARE STILL IN MEMORY
            Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;///////////////////////////////////////////////////////////

            wndHighScoresForm    = new wndHighScores();
            wndEnterUserDataForm = new wndEnterUserData();
            wndGameForm          = new wndGame();

            //Pass the high scores form to the game form.  This way the high scores form may be displayed via the game form.
            wndGameForm.CopyHighScores = wndHighScoresForm;
        }