Ejemplo n.º 1
0
        public static QuizElementMultAnswers CreateQuizElement()
        {
            try
            {
                string question = QuizElement.promptEnterQuestion();

                var answerList = new List <Answer> {
                };

                var cont = true;
                while (cont)
                {
                    Console.WriteLine("Please enter a possible answer, alternatively simply press enter to go to the next step.");
                    Console.Write("> ");
                    var input = Console.ReadLine();

                    if (input.Equals(""))
                    {
                        cont = false;
                    }
                    else
                    {
                        Console.WriteLine("Is this answer true? (Type y/n for true/false)");
                        Console.Write("> ");
                        var input2 = Console.ReadLine().ToLower();

                        if (input2.Equals("y"))
                        {
                            answerList.Add(new Answer(input, true));
                        }
                        else if (input2.Equals("n"))
                        {
                            answerList.Add(new Answer(input, false));
                        }
                        else
                        {
                            throw new System.FormatException();
                        }
                    }
                }

                return(new QuizElementMultAnswers(question, answerList));
            }
            catch (System.FormatException)
            {
                Console.WriteLine("Invalid input! Please try again.");
                return(QuizElementMultAnswers.CreateQuizElement());
            }
        }
Ejemplo n.º 2
0
        public static QuizElementSingleAnswer CreateQuizElement()
        {
            try
            {
                string question = QuizElement.promptEnterQuestion();

                var answerList = new List <Answer> {
                };

                var cont = true;
                while (cont)
                {
                    Console.WriteLine("Please enter a possible answer, alternatively simply press enter to go to the next step.");
                    Console.Write("> ");
                    var input = Console.ReadLine();

                    if (input.Equals(""))
                    {
                        cont = false;
                    }
                    else
                    {
                        answerList.Add(new Answer(input, false));
                    }
                }

                Console.WriteLine("Your answers are: ");
                for (int i = 0; i < answerList.Count; i++)
                {
                    Console.WriteLine(i + 1 + ". " + answerList[i].text);
                }
                Console.WriteLine("Which answer is correct?");
                Console.Write("> ");
                var correctAnwer = Int32.Parse(Console.ReadLine());
                answerList[correctAnwer].isTrue = true;

                return(new QuizElementSingleAnswer(question, answerList));
            }
            catch (System.FormatException)
            {
                Console.WriteLine("Invalid input! Please try again.");
                return(QuizElementSingleAnswer.CreateQuizElement());
            }
        }