Пример #1
0
        /// <summary>
        /// Checks answer to see if it is correct or incorrect
        /// </summary>
        /// <param name="e"></param>
        private void CheckAnswer(KeyEventArgs e)
        {
            ///Exception handling for the normal method
            try
            {
                if (e.Key == Key.Enter)
                {
                    //Check and see if the answer is right, if it is add one to score
                    if (Int32.Parse(AnswerBox.Text) == game.getAnswer(counter))
                    {
                        counter++;
                        GradeLabel.Content = "Correct";
                        player.addUserScore();
                    }
                    else
                    {
                        counter++;
                        GradeLabel.Content = "Incorrect";
                    }

                    if (counter >= 10)
                    {
                        MyTimer.Stop();
                        counter = 0;
                        FinalScoreWindow final = new FinalScoreWindow(player);
                        if (player.getUserScore() <= 4)
                        {
                            final.BackgroundImage.ImageSource = new BitmapImage(new Uri(@"Images/LizardMan.jpg", UriKind.Relative));
                        }
                        else if (player.getUserScore() >= 5 || player.getUserScore() <= 7)
                        {
                            final.BackgroundImage.ImageSource = new BitmapImage(new Uri(@"Images/Background1.jpg", UriKind.Relative));
                        }
                        else
                        {
                            final.BackgroundImage.ImageSource = new BitmapImage(new Uri(@"Images/Background2.jpg", UriKind.Relative));
                        }

                        final.ShowDialog();
                    }
                    else
                    {
                        // List the new Question
                        QuestionLabel.Content = game.questionToString(counter);
                    }

                    AnswerBox.Text = "";
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }