예제 #1
0
        private static Quiz getMultiplication(int rangeFrom, int rangeTo)
        {
            Quiz quiz = new Quiz();
            int  num1 = MRandom.getRandomNumber(rangeFrom, rangeTo);
            int  num2 = MRandom.getRandomNumber(rangeFrom, rangeTo);
            int  ans  = num1 * num2;

            quiz.question = num1.ToString() + " X " + num2.ToString();
            quiz.answer   = ans.ToString();
            return(quiz);
        }
예제 #2
0
        private void nextQuiz()
        {
            try
            {
                int rangeFrom = Convert.ToInt32(tbRangeFrom.Text);
                int rangeTo   = Convert.ToInt32(tbRangeTo.Text);
                if (rangeFrom >= rangeTo)
                {
                    throw new Exception("Range must contain at least two numbers");
                }
                int           timeInterval = Convert.ToInt32(tbTimeInterval.Text);
                Quiz.QuizType quizType;
                if (cbQuiz.SelectedValue.ToString() == "Random!")
                {
                    int n = MRandom.getRandomNumber(0, 4);
                    quizType = (Quiz.QuizType)Enum.Parse(typeof(Quiz.QuizType), n.ToString());
                }
                else
                {
                    quizType = (Quiz.QuizType)Enum.Parse(typeof(Quiz.QuizType), cbQuiz.SelectedValue.ToString());
                }
                quiz = QuizFactory.getQuiz(quizType, timeInterval, rangeFrom, rangeTo);

                //set quiz
                lbQuiz.Content    = quiz.question;
                lbStatues.Content = statusMsg +
                                    "The next question is worth " +
                                    quiz.score +
                                    "points!";

                //Set timer
                if (Convert.ToBoolean(cbLimitedTime.IsChecked))
                {
                    time = 0; //reset current time
                    dispatcherTimer.Start();
                    //Set timer visiblity
                    if (pbTime.Visibility == System.Windows.Visibility.Hidden)
                    {
                        pbTime.Visibility = System.Windows.Visibility.Visible;;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        private static Quiz getDivision(int rangeFrom, int rangeTo)
        {
            Quiz quiz = new Quiz();
            int  div1 = MRandom.getRandomNumber(rangeFrom, rangeTo);

            //div1 should not be 0
            while (div1 == 0)
            {
                div1 = MRandom.getRandomNumber(rangeFrom, rangeTo);
            }
            int div2 = MRandom.getRandomNumber(rangeFrom, rangeTo);
            int mult = div1 * div2;

            quiz.question = mult.ToString() + " ÷ " + div1.ToString();
            quiz.answer   = div2.ToString();
            return(quiz);
        }