Exemplo n.º 1
0
        public override bool SetupByUserInput()
        {
            List <QuizOption> quizOptions = new List <QuizOption>();

            Console.WriteLine("Please write down your question");
            string question = Console.ReadLine();

            Console.WriteLine("How many options you you wanna have ?");
            string numberString = Console.ReadLine();
            int    numberInt    = Int32.Parse(numberString);
            bool   correctBool  = false;

            for (int i = 1; i < numberInt + 1; i++)
            {
                Console.WriteLine("Please insert Option nr. " + i);
                string text = Console.ReadLine();

                Console.WriteLine("Is this option correct ? Write true or false");
                string correctString = Console.ReadLine();
                if (correctString == "true")
                {
                    correctBool = true;
                }
                else if (correctString == "false")
                {
                    correctBool = false;
                }

                QuizOption option = new QuizOption();
                option.text    = text;
                option.correct = correctBool;
                quizOptions.Add(option);
            }

            this.question = question;
            QuizOption[] array = quizOptions.ToArray();
            this.options = array;
            return(true);

            return(true);
        }
Exemplo n.º 2
0
        public override bool CheckAnswer(string _answer)
        {
            bool correct = false;

            string[] allPlayerAnswers = _answer.Split(",");
            for (int i = 0; i < this.options.Length; i++)
            {
                QuizOption option = this.options[i];
                for (int j = 0; j < allPlayerAnswers.Length; j++)
                {
                    if (allPlayerAnswers[j] == option.text && option.correct == true)
                    {
                        correct = true;
                        continue;
                    }
                    else if (allPlayerAnswers[j] == option.text && option.correct == false)
                    {
                        correct = false;
                        return(correct);
                    }
                }
            }
            return(correct);
        }