public static string[] GetWordlist(int sortBy, string listName) { int count = 1; wordlist = Wordlist.LoadList(listName); string[] words = new string[1 + wordlist.Count()]; for (int i = 0; i < wordlist.Languages.Length; i++) { words[0] += wordlist.Languages[i] + "\t"; } Action <string[]> showtrans = (x) => { for (int i = 0; i < x.Length; i++) { words[count] += x[i] + "\t"; } count++; }; wordlist.List(sortBy, showtrans); return(words); }
public void Practice(string[] args) { if (args.Length == 2) { string listName = args[1]; string translateThis, rightWord, answer; try { Wordlist wordlist = Wordlist.LoadList(listName); do { Console.WriteLine($"Practicing on {listName}.dat\n" + $"Enter empty line to quit;"); Word word = wordlist.GetWordToPractice(); translateThis = word.Translations[word.FromLanguage]; rightWord = word.Translations[word.ToLanguage]; Console.Write($"\nWhat is {translateThis.ToUpper()}\n" + $"on {wordlist.Languages[word.ToLanguage].ToUpper()}:"); answer = Console.ReadLine(); if (answer.ToLower().Equals(rightWord)) { Console.WriteLine("Thats Correct!!\n"); } else if (answer.Equals("")) { break; } else { Console.WriteLine($"You are wrong, sir!\n" + $"The correct word is {rightWord.ToUpper()}\n"); } } while (!answer.Equals("")); } catch (FileNotFoundException) { Console.WriteLine("List Not Found!"); PrintErrorInstructionMessage(); } } else { PrintErrorInstructionMessage(); } }
public void Words(string[] args) { if (args.Length == 3) { string listName = args[1]; try { int intLanguage; Wordlist wordlist = Wordlist.LoadList(listName); Action <string[]> showtrans = (x) => { foreach (var item in x) { Console.Write(item + " "); } Console.WriteLine(); }; if (wordlist.Languages.Any(args[2].Contains)) { intLanguage = Array.IndexOf(wordlist.Languages, args[2]); } else { Console.WriteLine("Language not found!"); goto here; } wordlist.List(intLanguage, showtrans); here :; } catch (FileLoadException) { Console.WriteLine("List not found"); PrintErrorInstructionMessage(); } } else { PrintErrorInstructionMessage(); } }
public void Remove(string[] args) { if (args.Length > 3) { PrintErrorInstructionMessage(); } string listName = args[1]; int intLanguage; string[] words = args.Skip(3).ToArray(); try { Wordlist wordlist = Wordlist.LoadList(listName); if (wordlist.Languages.Any(args[2].Contains)) { intLanguage = Array.IndexOf(wordlist.Languages, args[2]); } else { Console.WriteLine("Language not found!"); goto here; } for (int i = 0; i < args.Length - 3; i++) { if (wordlist.Remove(intLanguage, words[i])) { wordlist.Save(); Console.WriteLine($"-{words[i]} removed!"); } else { Console.WriteLine($"-{words[i]} not dosent exist!"); } } here :; } catch (FileNotFoundException) { Console.WriteLine("List not found"); PrintErrorInstructionMessage(); } }
private void listBox_WordLists_SelectedIndexChanged(object sender, EventArgs e) { ListBox langaugeBox = listBoxLanguages; if (listBoxWordLists.SelectedItem != null) { string SelectedItem = listBoxWordLists.SelectedItem.ToString(); ShowLanguages = Wordlist.LoadList(SelectedItem); langaugeBox.Items.Clear(); foreach (var language in ShowLanguages.Languages) { langaugeBox.Items.Add(language); } labelwordCount.Text = ShowLanguages.Count().ToString(); } }
private void setActiveWordListToolStripMenuItem_Click(object sender, EventArgs e) { using (Form2 newform2 = new Form2()) { if (newform2.ShowDialog() == DialogResult.OK) { ActiveList = Wordlist.LoadList(newform2.ShowLanguages.Name); dataGridView1.Columns.Clear(); foreach (string language in ActiveList.Languages) { dataGridView1.Columns.Add($"column{language}", language); } dataGridView1.Rows.Clear(); ActiveList.List(0, ShowTranslations()); buttonPractice.Enabled = true; buttonaddWord.Enabled = true; } } }
public void Count(string[] args) { if (args.Length == 2) { string listName = args[1]; try { Wordlist wordlist = Wordlist.LoadList(listName); Console.WriteLine($"There are {wordlist.Count()} words in {listName}.dat"); } catch (FileNotFoundException) { Console.WriteLine("List not found!"); PrintErrorInstructionMessage(); } } else { PrintErrorInstructionMessage(); } }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Use any of the following parameters:"); Console.WriteLine($"-lists"); Console.WriteLine($"-new < listName > < language 1 > < language 2 > .. < langauge n > "); Console.WriteLine($"-add < listName > "); Console.WriteLine($"-remove < listName > < language > < word 1 > < word 2 > .. < word n > "); Console.WriteLine($"-words < listname > < sortByLanguage > "); Console.WriteLine($"-count < listName > "); Console.WriteLine($"-practice < listName > "); } else { foreach (var arg in args) { arg.ToLower(); } string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Lab4"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string s = args[0]; switch (s) { case "-lists": Lists = Wordlist.GetLists(); if (Lists.Length == 0) { Console.WriteLine("No lists have been added"); } else { foreach (string list in Lists) { Console.WriteLine(list); } } break; case "-new": string message = "A list must contain a name and at least two languages"; if (args.Length <= 3) { Console.WriteLine(message); break; } else { Wordlist newList = new Wordlist(args[1], paramsArrNew(args)); newList.Save(); goto case "-add"; } case "-add": Lists = Wordlist.GetLists(); if (Lists.Length == 0) { Console.WriteLine("No lists have been added"); } else if (!Lists.Contains(args[1])) { Console.WriteLine($"No list with listname '{args[1]}' could be found"); } else { Wordlist addtranslations = Wordlist.LoadList(args[1]); int count = 0; bool loop = true; Console.WriteLine(); Console.WriteLine("Press enter (empty line) to stop input of words"); Console.WriteLine(); while (loop) { string[] translation = new string[addtranslations.Languages.Length]; Console.Write($"Add a new word in '{addtranslations.Languages[0]}': "); string firstWord = Console.ReadLine(); if (string.IsNullOrEmpty(firstWord)) { loop = false; } else { translation[0] += firstWord; for (int i = 1; i < addtranslations.Languages.Length; i++) { Console.Write($"Translate '{firstWord}' to '{addtranslations.Languages[i]}': "); string newWord = Console.ReadLine(); if (string.IsNullOrEmpty(newWord)) { loop = false; } else { translation[i] += newWord; } } addtranslations.Add(translation); translation = null; } count++; } Console.WriteLine(); Console.WriteLine($"{count} words was added to '{args[1]}'"); Console.WriteLine(); addtranslations.Save(); } break; case "-remove": Lists = Wordlist.GetLists(); if (Lists.Length == 0) { Console.WriteLine("No lists have been added"); } else if (args.Length < 4) { Console.WriteLine("The 'remove-command' requires a listname, a language and at least one word to remove"); } else if (!Lists.Contains(args[1])) { Console.WriteLine($"No list with listname '{args[1]}' could be found"); } else { Wordlist removeWord = Wordlist.LoadList(args[1]); if (!removeWord.Languages.Contains(args[2])) { Console.WriteLine($"'{args[1]}' did not contain the language 'args[2]'"); } else { int val = 0; string[] words = paramsArrRemove(args); foreach (string word in words) { for (int i = 0; i < removeWord.Languages.Length; i++) { if (removeWord.Languages[i] == args[2]) { val = i; } } if (removeWord.Remove(val, word)) { Console.WriteLine($"{word} has been removed"); } else { Console.WriteLine($"{word} has not been removed because it didn't exist in given list"); } removeWord.Save(); } } } break; case "-words": Lists = Wordlist.GetLists(); if (Lists.Length == 0) { Console.WriteLine("No lists have been added"); } else if (args.Length <= 1) { Console.WriteLine("The 'words-command' requires at least a listname"); } else if (!Lists.Contains(args[1])) { Console.WriteLine($"No list with listname '{args[1]}' could be found"); } else { Wordlist listWords = Wordlist.LoadList(args[1]); Action <string[]> showTranslations = (translations) => { foreach (string translation in translations) { Console.Write($"{translation,-20}"); } Console.WriteLine(); }; if (args.Length == 3 && listWords.Languages.Contains(args[2])) { foreach (string language in listWords.Languages) { Console.Write($"{language,-20}"); } Console.WriteLine(); int num = Array.IndexOf(listWords.Languages, args[2]); listWords.List(num, showTranslations); } else if (args.Length == 2) { foreach (string language in listWords.Languages) { Console.Write($"{language,-20}"); } Console.WriteLine(); listWords.List(0, showTranslations); } else if (!listWords.Languages.Contains(args[2])) { Console.WriteLine($"'{listWords.Name}' doesn't contain any words in '{args[2]}'"); } } break; case "-count": Lists = Wordlist.GetLists(); if (Lists.Length == 0) { Console.WriteLine("No lists have been added"); } else if (args.Length <= 1) { Console.WriteLine("The 'count-command' requires at least a listname"); } else if (!Lists.Contains(args[1])) { Console.WriteLine($"No list with listname '{args[1]}' could be found"); } else { Wordlist numOfWordsInLanguage = Wordlist.LoadList(args[1]); Console.WriteLine($"The number of words in your list {args[1]} is :{numOfWordsInLanguage.Count()}"); } break; case "-practice": Lists = Wordlist.GetLists(); if (Lists.Length == 0) { Console.WriteLine("No lists have been added"); } else if (args.Length <= 1) { Console.WriteLine("The 'practice-command' requires at least a listname"); } else if (!Lists.Contains(args[1])) { Console.WriteLine($"No list with listname '{args[1]}' could be found"); } else { Wordlist practiceWords = Wordlist.LoadList(args[1]); int correctAnswer = 0; int wordsPracticed = 0; while (true) { Word word = practiceWords.GetWordToPractice(); string[] strArr = word.Translations; string input = ""; Console.WriteLine(); Console.Write($"Translate {word.Translations[word.FromLanguage]} to {practiceWords.Languages[word.ToLanguage]}: "); input = Console.ReadLine().ToLower(); if (string.IsNullOrEmpty(input) || string.IsNullOrWhiteSpace(input)) { break; } if (input == word.Translations[word.ToLanguage]) { Console.WriteLine("correct answer"); correctAnswer++; wordsPracticed++; } else if (input != word.Translations[word.ToLanguage] && !string.IsNullOrEmpty(input) && !string.IsNullOrWhiteSpace(input)) { Console.WriteLine("incorrect answer"); wordsPracticed++; } } Console.WriteLine("\nPractice has been ended"); Console.WriteLine($"\nYou practiced {wordsPracticed} words in total"); Console.WriteLine($"You got {correctAnswer} out of {wordsPracticed} correct answers"); } break; default: Console.WriteLine("There was something wrong with your command"); break; } } }
public void Add(string[] args) { if (args.Length == 2) { string listName = args[1]; string word = ""; try { Wordlist wordlist = Wordlist.LoadList(listName); do { Console.WriteLine($"Adding words to wordlist: {listName}.dat"); Console.WriteLine("Exit by type empty word!! Your current word will be lost"); string[] translation = new string[wordlist.Languages.Length]; for (int i = 0; i < wordlist.Languages.Length; i++) { Console.Write($"-Enter the word on {wordlist.Languages[i].ToUpper()}: "); word = Console.ReadLine(); if (!word.Equals("")) { if (word.All(char.IsLetter)) { word = word.ToLower(); translation[i] = word; } else { throw new Exception("This is not a word.... only use A-Z"); } } else { goto start; } } translation = translation.Where(x => !string.IsNullOrEmpty(x)).ToArray(); wordlist.Add(translation); Console.WriteLine("\n"); wordlist.Save(); start :; } while (!word.Equals("")); wordlist.Save(); } catch (FileNotFoundException) { Console.WriteLine("List not found"); PrintErrorInstructionMessage(); } } else { PrintErrorInstructionMessage(); } }