コード例 #1
0
        static void Remove(string[] args)
        {
            GuardClauses.TriedToRemoveNothing(args);
            var loadedList = WordList.LoadList(args[1]);

            GuardClauses.LoadedListReturnsNull(loadedList, args[1]);

            int index = Array.FindIndex(loadedList.Languages, l => l.Contains(args[2]));

            GuardClauses.TheLanguageDoesNotExistInThisList(index);

            string[] word = args.Skip(3).ToArray();
            for (int i = 0; i < word.Length; i++)
            {
                if (loadedList.Remove(index, word[i]) == false)
                {
                    Console.WriteLine($"The word '{word[i]}' does not exist in this list.");
                }

                else
                {
                    Console.WriteLine($"Removed '{word[i]}' from the list.");
                }
            }
            loadedList.Save();
        }
コード例 #2
0
        static void AddWords(string[] args)
        {
            GuardClauses.NoSelectedList(args);
            var loadedList = WordList.LoadList(args[1]);

            GuardClauses.LoadedListReturnsNull(loadedList, args[1]);

            bool  addWords       = true;
            Regex forbiddenChars = new Regex("[0-9;\r\n]+");

            while (addWords)
            {
                string[] translations = new string[loadedList.Languages.Length];
                for (int i = 0; i < loadedList.Languages.Length; i++)
                {
                    Console.Write($"{loadedList.Languages[i].ToUpper()}: ");
                    translations[i] = Console.ReadLine();
                    if (translations[i] == "")
                    {
                        addWords = false; break;
                    }

                    translations[i] = forbiddenChars.Replace(translations[i], "").Trim();
                }
                if (!translations.Contains(""))
                {
                    loadedList.Add(translations);
                }
            }
            loadedList.Save();
        }
コード例 #3
0
        static void CountWordsInSelectedList(string[] args)
        {
            GuardClauses.NoSelectedList(args);
            var loadedList = WordList.LoadList(args[1]);

            GuardClauses.LoadedListReturnsNull(loadedList, args[1]);

            Console.WriteLine($"There's {loadedList.Count()} words in '{loadedList.Name}'");
        }
コード例 #4
0
        static void CreateNewList(string[] args)
        {
            GuardClauses.InputMissingParameters(args);
            WordList newList = new WordList(args[1], args.Skip(2).ToArray());

            newList.Save();

            Console.WriteLine($"A new list called {args[1]} was successfully created.");
            AddWords(args);
        }
コード例 #5
0
        static void SortList(string[] args)
        {
            GuardClauses.NoSelectedList(args);
            var loadedList = WordList.LoadList(args[1]);

            GuardClauses.LoadedListReturnsNull(loadedList, args[1]);
            GuardClauses.SelectedListDoesntContainWords(loadedList);

            if (args.Length < 3)
            {
                loadedList.List(0, ShowTranslation);
            }
            else
            {
                GuardClauses.SelectedListDoesntContainLanguage(loadedList, args[2]);
                string language = args[2];
                int    index    = Array.FindIndex(loadedList.Languages, l => l.Contains(language));
                loadedList.List(index, ShowTranslation);
            }
        }
コード例 #6
0
        static void PracticeWords(string[] args)
        {
            GuardClauses.NoSelectedList(args);
            var loadedList = WordList.LoadList(args[1]);

            GuardClauses.LoadedListReturnsNull(loadedList, args[1]);
            GuardClauses.SelectedListDoesntContainWords(loadedList);
            PracticeConsole.ResetPractice();
            while (true)
            {
                Word            randomWord   = loadedList.GetWordToPractice();
                PracticeConsole practiceMode = new PracticeConsole(randomWord, loadedList);
                practiceMode.Play();

                string userInput = Console.ReadLine();
                if (userInput == "")
                {
                    practiceMode.PrintTotalScore();
                    break;
                }
                practiceMode.PrintRightOrWrong(userInput);
            }
        }