예제 #1
0
        // Button for the Quizzard Page.
        private void GoQuizzard(object sender, RoutedEventArgs e)
        {
            name = pName.Text;
            if (string.IsNullOrEmpty(name))
            {
                pName.Text = "  Enter your name";
                return;
            }

            var player = engine.CreateQuizzardPlayer(name);

            this.engine.Player = (QuizzardPlayer)player;
            QuizzardInitialPage quizzardInitialPage = new QuizzardInitialPage(this.engine);

            this.NavigationService.Navigate(quizzardInitialPage);
        }
        // We take the question and the four answers as strings when the Quizzard presses on the AddQuestion button

        private void AddQuestionButton(object sender, RoutedEventArgs e)
        {
            this.questionText = Question.Text;
            answerACorrect    = AnswerA.Text;
            answerB           = AnswerB.Text;
            answerC           = AnswerC.Text;
            answerD           = AnswerD.Text;
            IQuestion question;

            Validator.CheckIfStringArrayHasNullOrEmpty(new string[] { questionText, answerACorrect, answerB, answerC, answerD }, "Quizzard question or answer cannot be null or empty!");

            if (rBtnNormal.IsChecked == true)
            {
                question = this.engine.CreateNormalQuestion(questionText, DifficultyLevel.Easy, CategoryType.Random);
            }
            else if (rBtnBonus.IsChecked == true)
            {
                int multiplyBy = (int)this.multiValue;

                Validator.CheckIntRange(multiplyBy, GlobalConstants.MinPointsMultiplier, GlobalConstants.MaxPointsMultiplier, string.Format(GlobalConstants.NumberMustBeBetweenMinAndMax, "Point's multiplier", GlobalConstants.MinPointsMultiplier, GlobalConstants.MaxPointsMultiplier));
                question = this.engine.CreateBonusQuestion(questionText, DifficultyLevel.Easy, CategoryType.Random, multiplyBy);
            }
            else
            {
                int time = (int)this.timerValue;

                Validator.CheckIntRange(time, GlobalConstants.MinTimeForAnswer, GlobalConstants.MaxTimeForAnswer, string.Format(GlobalConstants.NumberMustBeBetweenMinAndMax, "Question's timer", GlobalConstants.MinTimeForAnswer, GlobalConstants.MaxTimeForAnswer));
                question = this.engine.CreateTimedQuestion(questionText, DifficultyLevel.Easy, CategoryType.Random, time);
            }

            var anwerOne    = this.engine.CreateAnswer(answerACorrect, true);
            var answerTwo   = this.engine.CreateAnswer(answerB, false);
            var answerThree = this.engine.CreateAnswer(answerC, false);
            var answerFour  = this.engine.CreateAnswer(answerD, false);

            question.AddAnswerFluent(anwerOne).AddAnswerFluent(answerTwo).AddAnswerFluent(answerThree).AddAnswerFluent(answerFour);

            QuizzardPlayer quizzard = (QuizzardPlayer)engine.Player;

            quizzard.AddQuestion(question);

            QuizzardInitialPage quizzardInitialPage = new QuizzardInitialPage(this.engine);

            this.NavigationService.Navigate(quizzardInitialPage);
        }