Beispiel #1
0
        private void AddOptionsToQuestion(Question question)
        {
            Console.WriteLine("Add from 2 to 5 question answers");

            for (int i = 0; i < 5; i++)
            {
                if (i >= 2)
                {
                    if (!InputsOperator.ProcessYesNoInput("Add an answer for current question Y/N?"))
                    {
                        break;
                    }
                }

                Console.WriteLine("Enter an answer");

                string content   = Console.ReadLine();
                bool   isItRight = InputsOperator.ProcessYesNoInput("Is it right answer? Y/N?");

                question.Answers.Add(new Answer(content, isItRight));
            }

            if (!CheckForRightAnswers(question.Answers))
            {
                SetRightAnswers(question);
            }

            Console.WriteLine("Question added");
        }
Beispiel #2
0
        private bool AskQuestion(Question question)
        {
            bool[] answerResult = new bool[question.Answers.Count];
            bool   result       = false;

            while (true)
            {
                Console.WriteLine(question.QuestionContent);

                Console.WriteLine();

                Console.WriteLine("Choose answer:");

                for (int i = 0; i < question.Answers.Count; i++)
                {
                    Console.WriteLine($"{i + 1} - {question.Answers[i].Content}");
                    answerResult[i] = false;
                }

                ConsoleKeyInfo key = Console.ReadKey(true);
                int            value;

                if (int.TryParse(key.KeyChar.ToString(), out value))
                {
                    if (value <= question.Answers.Count)
                    {
                        Console.WriteLine($"You choose answer: {question.Answers[value - 1].Content}");
                        answerResult[value - 1] = true;

                        result = CheckAnswer(question, answerResult);

                        Console.WriteLine();
                        if (!InputsOperator.ProcessYesNoInput("Choose more right answers for current question? Y/N"))
                        {
                            Console.WriteLine();
                            break;
                        }
                    }
                }

                Console.WriteLine();
            }

            return(result);
        }
Beispiel #3
0
        public void CreateTest()
        {
            Console.WriteLine("Enter test theme");
            string testTheme = Console.ReadLine();

            Test test = new Test(testTheme);

            while (true)
            {
                if (InputsOperator.ProcessYesNoInput("Add a question for this test Y/N?"))
                {
                    CreateQuestion(test);
                }
                else
                {
                    FilesOperator.SaveTest(test);
                    break;
                }
            }
        }
Beispiel #4
0
        private void SetRightAnswers(Question question)
        {
            Console.WriteLine("There no right answers for current question");

            while (true)
            {
                Console.WriteLine("Choose number of answer that should be right");

                for (int i = 0; i < question.Answers.Count; i++)
                {
                    if (!question.Answers[i].IsItRight)
                    {
                        Console.WriteLine($"{i + 1} - {question.Answers[i].Content}");
                    }
                }

                while (true)
                {
                    string input = Console.ReadLine();
                    if (AnswerCheck(input, question.Answers))
                    {
                        int i = int.Parse(input);

                        if (InputsOperator.ProcessYesNoInput($"You want answer {i} - {question.Answers[i - 1].Content} to be correct?"))
                        {
                            question.Answers[i - 1].IsItRight = true;
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Bad input");
                    }
                }

                if (!InputsOperator.ProcessYesNoInput("Add more right answers?"))
                {
                    break;
                }
            }
        }