Ejemplo n.º 1
0
        private void btn_sortList_Click(object sender, EventArgs e) // SortList-button
        {
            LoadWordList wordList  = new LoadWordList(WordList.LoadList);
            WordList     wordList1 = wordList.Invoke(localPath);

            string[] languages      = wordList1.Languages;
            string   sortByLanguage = Interaction.InputBox("Type the language you want to sort in...", "Sort by language");

            Action <string[]> showTranslations = (string[] translations) =>
            {
                string output = string.Join(',', translations);

                listView1.Items.Add(output);
            };

            listView1.Items.Clear();
            if (sortByLanguage == "")
            {
                wordList1.List(0, showTranslations);
                return;
            }

            for (int i = 0; i < languages.Length; i++)
            {
                if (sortByLanguage == languages[i])
                {
                    wordList1.List(i, showTranslations);
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e) //New word-button.
        {
            if (listView1 != null)
            {
                LoadWordList wordList      = new LoadWordList(WordList.LoadList);
                WordList     wordList1     = wordList.Invoke(localPath);
                string[]     languages     = wordList1.Languages;
                bool         areWordsAdded = false;

                while (true)
                {
                    string[] translations     = new string[wordList1.Languages.Length];
                    string   firstTranslation = translations[0] = Interaction.InputBox($"Type a word in {wordList1.Languages[0]}");

                    if (firstTranslation == string.Empty)
                    {
                        break;
                    }

                    for (int i = 1; i < translations.Length; i++)
                    {
                        string wordsToTranslate;
                        do
                        {
                            wordsToTranslate = Interaction.InputBox($"Translate {firstTranslation} to {wordList1.Languages[i]}");
                        } while (wordsToTranslate == string.Empty);

                        translations[i] = wordsToTranslate;
                    }
                    wordList1.Add(translations);
                    areWordsAdded = true;
                }
                if (areWordsAdded)
                {
                    wordList1.Save();
                }
                label1.Text = "Number of words: " + wordList1.Count().ToString();
            }
            else if (listView1 == null)
            {
                MessageBox.Show("You have to choose a list to add words to.", "Warning!");
                btn_NewWord.Enabled = false;
            }
        }
Ejemplo n.º 3
0
        private void btn_practice_Click(object sender, EventArgs e) //Practice-button
        {
            LoadWordList wordList  = new LoadWordList(WordList.LoadList);
            WordList     wordList1 = wordList.Invoke(localPath);

            int totalGuesses   = 0;
            int correctAnswers = 0;

            listView1.Items.Clear();
            while (true)
            {
                Word word = wordList1.GetWordToPractice();

                string input = Interaction.InputBox(
                    $"Translate the \"{wordList1.Languages[word.FromLanguage]}\" word: " +
                    $"{word.Translations[word.FromLanguage]}, " +
                    $"to \"{wordList1.Languages[word.ToLanguage]}\"" +
                    $"\n\nLeave empty to exit"
                    , "Practice: Translations input");

                if (input == "" || input == " ")
                {
                    MessageBox.Show($"You guessed correct {correctAnswers} out of {totalGuesses} times.", "Result");

                    break;
                }
                else if (input == word.Translations[word.ToLanguage])
                {
                    MessageBox.Show("That is the correct answer!", "Correct");

                    totalGuesses++;
                    correctAnswers++;
                    continue;
                }
                else
                {
                    MessageBox.Show("Wrong answer. :( \n" +
                                    "Let's try a another word.", "Wrong");

                    totalGuesses++;
                    continue;
                }
            }
        }
Ejemplo n.º 4
0
        private void button3_Click(object sender, EventArgs e) //remove-button
        {
            LoadWordList wordList  = new LoadWordList(WordList.LoadList);
            WordList     wordList1 = wordList.Invoke(localPath);

            string[] languages       = wordList1.Languages;
            string   languagesInList = Interaction.InputBox("Choose the language you want to remove a word from: ");

            string inputRemoveWord;
            int    langIndex = -1;

            inputRemoveWord = Interaction.InputBox("Please enter word(s) you wish to remove." +
                                                   "\nSeparate the words with semicolon", "Remove word");
            string[] wordsToBeRemoved = inputRemoveWord.Split(' ', ';').ToArray <string>();


            for (int i = 0; i < languages.Length; i++)
            {
                if (languages[i].Equals(languagesInList, StringComparison.InvariantCultureIgnoreCase))
                {
                    langIndex = i;
                    break;
                }
            }

            if (langIndex > -1)
            {
                foreach (var w in wordsToBeRemoved)
                {
                    if (wordList1.Remove(langIndex, w))
                    {
                        MessageBox.Show($"{w} was removed from list.");
                    }
                    else
                    {
                        MessageBox.Show($"Could not find the word {w}");
                    }
                }
                wordList1.Save();
                label1.Text = "Number of words: " + wordList1.Count().ToString();
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            WordList.CreateFolder();

            if (args.Count() == 0)
            {
                PrintUsage();
            }
            else if (args[0] == "-lists")
            {
                foreach (string s in WordList.GetLists())
                {
                    Console.WriteLine(Path.GetFileNameWithoutExtension(s));
                }
            }
            else if (args[0] == "-practice")
            //Returns random word to the user to translate
            {
                if (args.Length < 1)
                {
                    Console.WriteLine("Enter listname to begin word practice.");
                    return;
                }
                LoadWordList wordList  = new LoadWordList(WordList.LoadList);
                WordList     wordList1 = wordList.Invoke(args[1]);

                int totalGuesses   = 0;
                int correctAnswers = 0;

                while (true)
                {
                    Word word = wordList1.GetWordToPractice();
                    Console.WriteLine(
                        $"Translate the \"{wordList1.Languages[word.FromLanguage]}\" word: " +
                        $"{word.Translations[word.FromLanguage]}, " +
                        $"to \"{wordList1.Languages[word.ToLanguage]}\"");

                    string input = Console.ReadLine();

                    if (input == "" || input == " ")
                    {
                        Console.WriteLine($"You guessed correct {correctAnswers} out of {totalGuesses} times.");
                        Console.ReadKey();
                        break;
                    }
                    else if (input == word.Translations[word.ToLanguage])
                    {
                        Console.WriteLine("That is the correct answer!");
                        totalGuesses++;
                        correctAnswers++;
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("Wrong answer. Try again.");
                        totalGuesses++;
                        continue;
                    }
                }
            }
            else if (args[0] == "-remove")
            {
                if (args.Length < 4)
                {
                    Console.WriteLine("You have entered too few arguments.");
                    return;
                }

                LoadWordList wordList         = new LoadWordList(WordList.LoadList);
                WordList     wordList1        = wordList.Invoke(args[1]);
                string[]     languages        = wordList1.Languages;
                string       lang             = args[2];
                string[]     wordsToBeRemoved = args[3..];
Ejemplo n.º 6
0
        private void button4_Click(object sender, EventArgs e) //New list - button
        {
            string localPath     = WordList.localPath;
            string fileNameInput = Interaction.InputBox("Enter the name of the new file.\n " + "Exclude the file type.", "New list", "", -1, -1);

            if (fileNameInput == "" || fileNameInput == " ")
            {
                MessageBox.Show("Invalid input. Filename can't be empty.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string languagesInput = Interaction.InputBox($"Enter which languages to be in \"{fileNameInput}\"." +
                                                             $"\nSeparate the languages with semicolon.", "Languages", "", -1, -1);
                if (languagesInput == "" || languagesInput == " ")
                {
                    MessageBox.Show("Invalid input. Languages needs to be added.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    try
                    {
                        var fileCreated = File.Create(Path.Combine(localPath, fileNameInput + ".dat"));
                        fileCreated.Close();
                        MessageBox.Show(fileNameInput + " created successfully.", "New list created");

                        File.WriteAllText(Path.Combine(localPath, fileNameInput + ".dat"), languagesInput);
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(ee.Message, "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                LoadWordList wordList      = new LoadWordList(WordList.LoadList);
                WordList     wordList1     = wordList.Invoke(fileNameInput);
                string[]     languages     = wordList1.Languages;
                bool         areWordsAdded = false;

                while (true)
                {
                    string[] translations     = new string[wordList1.Languages.Length];
                    string   firstTranslation = translations[0] = Interaction.InputBox($"Type a word in {wordList1.Languages[0]}");

                    if (firstTranslation == string.Empty)
                    {
                        break;
                    }

                    for (int i = 1; i < translations.Length; i++)
                    {
                        string wordsToTranslate;
                        do
                        {
                            wordsToTranslate = Interaction.InputBox($"Translate {firstTranslation} to {wordList1.Languages[i]}");
                        } while (wordsToTranslate == string.Empty);

                        translations[i] = wordsToTranslate;
                    }
                    wordList1.Add(translations);
                    areWordsAdded = true;
                }
                if (areWordsAdded)
                {
                    wordList1.Save();
                }
                label1.Text = "Number of words: " + wordList1.Count().ToString();
            }
        }