コード例 #1
0
        private Quiz.Question GetCurrentQuestionState()
        {
            List <Quiz.Answer> additionalAnswers = new List <Quiz.Answer>();

            if (this.viewMap.answerBoxes[2].answerBox.Text != "")
            {
                additionalAnswers.Add(new Quiz.Answer(
                                          this.viewMap.answerBoxes[2].answerBox.Text,
                                          this.viewMap.answerBoxes[2].isCorrectBox.Checked
                                          ));
            }

            if (this.viewMap.answerBoxes[3].answerBox.Text != "")
            {
                additionalAnswers.Add(new Quiz.Answer(
                                          this.viewMap.answerBoxes[3].answerBox.Text,
                                          this.viewMap.answerBoxes[3].isCorrectBox.Checked
                                          ));
            }

            Quiz.Question questionState = new Quiz.Question(
                this.viewMap.quiestionBox.Text,
                new Quiz.Answer(
                    this.viewMap.answerBoxes[0].answerBox.Text,
                    this.viewMap.answerBoxes[0].isCorrectBox.Checked
                    ),
                new Quiz.Answer(
                    this.viewMap.answerBoxes[1].answerBox.Text,
                    this.viewMap.answerBoxes[1].isCorrectBox.Checked
                    ),
                additionalAnswers
                );

            return(questionState);
        }
コード例 #2
0
        private Quiz.Quiz ParseXmlToObject(XmlDocument xmlDocument)
        {
            try
            {
                List <Quiz.Question> questions = new List <Quiz.Question>();
                foreach (XmlElement question in xmlDocument["quiz"]["questions"].ChildNodes)
                {
                    if (question["answers"].ChildNodes.Count >= 2)
                    {
                        List <Quiz.Answer> answers = new List <Quiz.Answer>();
                        foreach (XmlElement answer in question["answers"])
                        {
                            answers.Add(
                                new Quiz.Answer(
                                    answer["content"]["pl"].HasChildNodes ? answer["content"]["pl"].FirstChild.Value : "",
                                    Boolean.Parse(answer["is_correct"].FirstChild.Value)
                                    )
                                );
                        }

                        Quiz.Question fileQuestion = new Quiz.Question(
                            question["content"]["pl"].HasChildNodes ? question["content"]["pl"].FirstChild.Value : "",
                            answers[0],
                            answers[1],
                            answers.Skip(2).ToList()
                            );

                        questions.Add(fileQuestion);
                    }
                    else
                    {
                        // not enough answers
                        throw new Exception("File is invalid");
                    }
                }

                Quiz.Quiz parsedQuiz = new Quiz.Quiz(
                    xmlDocument["quiz"]["name"]["pl"].HasChildNodes ? xmlDocument["quiz"]["name"]["pl"].FirstChild.Value : "",
                    questions
                    );

                return(parsedQuiz);
            }
            catch (NullReferenceException exception)
            {
                //File has no appropriate fields
                throw new Exception("File is invalid");
            }
        }
コード例 #3
0
        public void loadQuestion(Quiz.Question question)
        {
            this.viewMap.ResetAnswerBoxes();

            this.viewMap.quiestionBox.Text = question.getQuestionContent();
            this.viewMap.answerBoxes.GetEnumerator().MoveNext();

            var boxesEnumerator = this.viewMap.answerBoxes.GetEnumerator();

            foreach (Quiz.Answer answer in question.GetAnswers())
            {
                if (boxesEnumerator.MoveNext())
                {
                    boxesEnumerator.Current.answerBox.Text       = answer.GetAnswerContent();
                    boxesEnumerator.Current.isCorrectBox.Checked = answer.isAnswerCorrect();
                }
                else
                {
                    throw new Exception("Too many answers in question, current view cannot handle it");
                }
            }
        }
コード例 #4
0
 public void SaveQuestionState(Quiz.Question question)
 {
     this.quiz.GetQuestions()[this.questionIndex] = question;
 }