コード例 #1
0
        /// <summary>
        /// This method will help get the UI set up for a new game and will
        /// work with other classes to reset variables for a new game.
        /// </summary>
        public void SetGameUp()
        {
            try
            {
                //Setting game variables
                newGame.GameType            = User.UsersLatestChoice;
                newGame.NumProblemsAnswered = 0;
                newGame.Score = 0;
                newGame.SetUpProblem();

                cancelled = false;

                //Clearing Displays
                FeedbackLabel.Content          = "";
                ProblemAnswerTextBox.IsEnabled = true;
                ProblemNumberLabel.Content     = "";
                ProblemAnswerTextBox.Text      = "";
                CurrentProblemLabel.Content    = "";
                operandDisplay = newGame.LeftOperand.ToString() + newGame.currOperator + newGame.RightOperand.ToString();
                CurrentProblemLabel.Content = operandDisplay;
                Keyboard.Focus(ProblemAnswerTextBox);
                Feedback2Label.Content = "";
                AnimalImage.SetValue(System.Windows.Controls.Image.SourceProperty, null);

                //Reseting Answers
                User.SetArrayToFalse();

                //Reseting timer
                startTime        = DateTime.Now;
                myTimer.Interval = new TimeSpan(0, 0, 1);
                myTimer.Start();
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + "." + ex.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// Works with the Game game class to check the user's answer and see if
        /// it was right. It will handle showing user correct/incorrect information
        /// and will display an animal if correct.
        /// </summary>
        private void CheckAnswer()
        {
            try
            {
                switch (newGame.GameType)
                {
                case "Addition":
                    if (newGame.AddNumberPair(ProblemAnswerTextBox.Text))
                    {
                        FeedbackLabel.Foreground = new SolidColorBrush(Colors.Green);
                        FeedbackLabel.Content    = "Correct!";
                        correct.Play();
                        GetAnimal();
                        User.WhichCorrect[newGame.NumProblemsAnswered - 1] = true;
                    }
                    else
                    {
                        FeedbackLabel.Foreground = new SolidColorBrush(Colors.Red);
                        FeedbackLabel.Content    = "Incorrect.";
                        incorrect.Play();
                        Feedback2Label.Content = "";
                        AnimalImage.SetValue(System.Windows.Controls.Image.SourceProperty, null);
                    }
                    break;

                case "Subtraction":
                    if (newGame.SubtractNumberPair(ProblemAnswerTextBox.Text))
                    {
                        FeedbackLabel.Foreground = new SolidColorBrush(Colors.Green);
                        FeedbackLabel.Content    = "Correct!";
                        correct.Play();
                        GetAnimal();
                        User.WhichCorrect[newGame.NumProblemsAnswered - 1] = true;
                    }
                    else
                    {
                        FeedbackLabel.Foreground = new SolidColorBrush(Colors.Red);
                        FeedbackLabel.Content    = "Incorrect.";
                        incorrect.Play();
                        Feedback2Label.Content = "";
                        AnimalImage.SetValue(System.Windows.Controls.Image.SourceProperty, null);
                    }
                    break;

                case "Multiplication":
                    if (newGame.MultiplyNumberPair(ProblemAnswerTextBox.Text))
                    {
                        FeedbackLabel.Foreground = new SolidColorBrush(Colors.Green);
                        FeedbackLabel.Content    = "Correct!";
                        correct.Play();
                        GetAnimal();
                        User.WhichCorrect[newGame.NumProblemsAnswered - 1] = true;
                    }
                    else
                    {
                        FeedbackLabel.Foreground = new SolidColorBrush(Colors.Red);
                        FeedbackLabel.Content    = "Incorrect.";
                        incorrect.Play();
                        Feedback2Label.Content = "";
                        AnimalImage.SetValue(System.Windows.Controls.Image.SourceProperty, null);
                    }
                    break;

                case "Division":
                    if (newGame.DivideNumberPair(ProblemAnswerTextBox.Text))
                    {
                        FeedbackLabel.Foreground = new SolidColorBrush(Colors.Green);
                        FeedbackLabel.Content    = "Correct!";
                        correct.Play();
                        GetAnimal();
                        User.WhichCorrect[newGame.NumProblemsAnswered - 1] = true;
                    }
                    else
                    {
                        FeedbackLabel.Foreground = new SolidColorBrush(Colors.Red);
                        FeedbackLabel.Content    = "Incorrect.";
                        incorrect.Play();
                        Feedback2Label.Content = "";
                        AnimalImage.SetValue(System.Windows.Controls.Image.SourceProperty, null);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + "." + ex.Message);
            }
        }