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(); }
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(); }
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}'"); }
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); } }
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); } }