Esempio n. 1
0
        public Menu()
        {
            MyAllQuizzez = new AllQuizzez();
            Accs         = new Dictionary <string, string>();
            Statistics   = new Dictionary <KeyValuePair <string, string>, int>();
            using (FileStream fileStream = new FileStream(PathAccs, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                using (StreamReader reader = new StreamReader(fileStream, Encoding.Default))
                {
                    Regex regexAccs      = new Regex(@"[A-z](\w*)");
                    Regex regexPasswords = new Regex(@"[0-9](\w*)");

                    while (!reader.EndOfStream)
                    {
                        string currentLine    = reader.ReadLine();
                        Match  matchAccs      = regexAccs.Match(currentLine);
                        Match  matchPasswords = regexPasswords.Match(currentLine);
                        Accs.Add(matchAccs.Value, matchPasswords.Value);
                    }
                }
            }

            using (FileStream fileStream = new FileStream(PathStats, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                using (StreamReader reader = new StreamReader(fileStream, Encoding.Default))
                {
                    Regex regexQuizzez    = new Regex("\".*?\"");
                    Regex regexLogins     = new Regex(@"[A-z](\w*)");
                    Regex regexTryAnswers = new Regex(@"[0-9](\w*)");

                    while (!reader.EndOfStream)
                    {
                        string currentLine     = reader.ReadLine();
                        Match  matchQuizzez    = regexQuizzez.Match(currentLine);
                        Match  matchLogins     = regexLogins.Match(currentLine);
                        Match  matchTryAnswers = regexTryAnswers.Match(currentLine);
                        Statistics.Add(new KeyValuePair <string, string>(matchQuizzez.Value.Trim('"'), matchLogins.Value), Convert.ToInt32(matchTryAnswers.Value));
                    }
                }
            }
            ShowLoginOrRegister(); // внутри будет инициализирован MyAccount
        }
Esempio n. 2
0
        public void StartMixedQuiz(AllQuizzez myAllQuizzez, Dictionary <KeyValuePair <string, string>, int> statistics)
        {
            Console.Clear();
            Console.WriteLine($"Начинаем смешанную викторину!");
            Console.WriteLine("\nДля продолжения нажмите любую кнопку...");
            Console.ReadKey();

            List <XmlQuestionData> allQuestions = new List <XmlQuestionData>();

            foreach (Quiz quiz in myAllQuizzez.AllQuizzezList)
            {
                foreach (XmlQuestionData question in quiz.QuizList)
                {
                    allQuestions.Add(question);
                }
            }

            Random rnd = new Random();

            for (int l = 0; l < allQuestions.Count; l++)
            {
                int             k     = rnd.Next(0, l);
                XmlQuestionData value = allQuestions[k];
                allQuestions[k] = allQuestions[l];
                allQuestions[l] = value;
            }
            allQuestions.RemoveRange(20, allQuestions.Count - 20);

            int countRightQuestions = 0;
            int i = 0;

            while (i < allQuestions.Count)
            {
                Console.Clear();
                Console.WriteLine(allQuestions[i].Question);
                Console.WriteLine();

                for (int j = 0; j < allQuestions[i].PossibleOptionsList.Count; j++)
                {
                    Console.WriteLine($"{j} - {allQuestions[i].PossibleOptionsList[j]}");
                }

                Console.WriteLine("\nВведите номер правильного ответа.");
                Console.WriteLine("Если их несколько, введите номера подряд без пробелов и запятых и нажмите Enter, иначе ответ не засчитается.");
                Console.Write("\nВвод: ");
                string userAnswers       = Console.ReadLine();
                int    countRightAnswers = 0;
                string tmp = "";
                foreach (char answer in userAnswers)
                {
                    if (userAnswers.Length != allQuestions[i].AnswersList.Count)
                    {
                        break;
                    }

                    foreach (int answ in allQuestions[i].AnswersList)
                    {
                        tmp += answ.ToString();
                    }

                    if (tmp.Contains(answer))
                    {
                        ++countRightAnswers;
                    }
                }
                if (countRightAnswers == allQuestions[i].AnswersList.Count)
                {
                    ++countRightQuestions;
                }
                i++;
            }

            KeyValuePair <string, string> del = new KeyValuePair <string, string>("Смешанная викторина", Login);

            statistics.Remove(del);
            statistics.Add(new KeyValuePair <string, string>("Смешанная викторина", Login), countRightQuestions);
            Menu.SaveStatisticsInFile(statistics);

            Console.Clear();
            Console.WriteLine("Викторина окончена!");
            Console.WriteLine($"Количество правильных ответов: {countRightQuestions} из {allQuestions.Count}.");
            Console.WriteLine();

            ShowMyPlaceInCurrentQuiz(statistics, "Смешанная викторина");
        }
Esempio n. 3
0
        public void StartQuiz(int choiceQuiz, AllQuizzez myAllQuizzez, Dictionary <KeyValuePair <string, string>, int> statistics)
        {
            Console.Clear();
            Console.WriteLine($"Начинаем викторину \"{myAllQuizzez.AllQuizzezList[choiceQuiz].QuizName}\".");
            Console.WriteLine("\nДля продолжения нажмите любую кнопку...");
            Console.ReadKey();

            int countRightQuestions = 0;
            int i = 0;

            while (i < myAllQuizzez.AllQuizzezList[choiceQuiz].QuizList.Count)
            {
                Console.Clear();
                Console.WriteLine(myAllQuizzez.AllQuizzezList[choiceQuiz].QuizList[i].Question);
                Console.WriteLine();
                for (int j = 0; j < myAllQuizzez.AllQuizzezList[choiceQuiz].QuizList[i].PossibleOptionsList.Count; j++)
                {
                    Console.WriteLine($"{j} - {myAllQuizzez.AllQuizzezList[choiceQuiz].QuizList[i].PossibleOptionsList[j]}");
                }
                Console.WriteLine("\nВведите номер правильного ответа.");
                Console.WriteLine("Если их несколько, введите номера подряд без пробелов и запятых и нажмите Enter, иначе ответ не засчитается.");
                Console.Write("\nВвод: ");
                string userAnswers       = Console.ReadLine();
                int    countRightAnswers = 0;
                string tmp = "";
                foreach (char answer in userAnswers)
                {
                    if (userAnswers.Length != myAllQuizzez.AllQuizzezList[choiceQuiz].QuizList[i].AnswersList.Count)
                    {
                        break;
                    }

                    foreach (int answ in myAllQuizzez.AllQuizzezList[choiceQuiz].QuizList[i].AnswersList)
                    {
                        tmp += answ.ToString();
                    }

                    if (tmp.Contains(answer))
                    {
                        ++countRightAnswers;
                    }
                }
                if (countRightAnswers == myAllQuizzez.AllQuizzezList[choiceQuiz].QuizList[i].AnswersList.Count)
                {
                    ++countRightQuestions;
                }
                i++;
            }

            KeyValuePair <string, string> del = new KeyValuePair <string, string>(myAllQuizzez.AllQuizzezList[choiceQuiz].QuizName, Login);

            statistics.Remove(del);
            statistics.Add(new KeyValuePair <string, string>(myAllQuizzez.AllQuizzezList[choiceQuiz].QuizName, Login), countRightQuestions);
            Menu.SaveStatisticsInFile(statistics);

            Console.Clear();
            Console.WriteLine("Викторина окончена!");
            Console.WriteLine($"Количество правильных ответов: {countRightQuestions} из {myAllQuizzez.AllQuizzezList[choiceQuiz].QuizList.Count}.");
            Console.WriteLine();

            ShowMyPlaceInCurrentQuiz(statistics, myAllQuizzez.AllQuizzezList[choiceQuiz].QuizName);
        }