Пример #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            WordList.CreateFolder();
            panel1.Visible = Visible;
            panel2.Visible = !Visible;
            panel3.Visible = !Visible;
            panel4.Visible = !Visible;
            panel5.Visible = !Visible;

            if (wordListObject == null)
            {
                exitToolStripMenuItem.Enabled         = false;
                practiceModeToolStripMenuItem.Enabled = false;
                button3.Enabled = false;
            }
        }
Пример #2
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..];
Пример #3
0
 public Form1()
 {
     InitializeComponent();
     WordList.CreateFolder();
 }
Пример #4
0
        private static void Main(string[] args)
        {
            WordList currentWordList = null;

            WordList.CreateFolder();

            if (args.Length == 0)
            {
                Console.WriteLine("Use any of the following parameters:");
                Console.WriteLine("-lists");
                Console.WriteLine("-new <list name> <language 1> <language 2> .. <language n>");
                Console.WriteLine("-add <list name>");
                Console.WriteLine("-remove <list name> <language> <word 1> <word 2> .. <word n>");
                Console.WriteLine("-words <list name> <sortByLanguage> ");
                Console.WriteLine("-count <list name>");
                Console.WriteLine("-practice <list name>");
            }

            try
            {
                switch (userInput(args)[0])
                {
                case "-lists":
                    ConsoleList();
                    break;

                case "-new":
                    ConsoleNew();
                    break;

                case "-add":
                    ConsoleAdd();
                    break;

                case "-remove":
                    ConsoleRemove();
                    break;

                case "-words":
                    ConsoleWords();
                    break;

                case "-count":
                    ConsoleCount();
                    break;

                case "-practice":
                    ConsolePractice();
                    break;
                }
            }
            catch (Exception)
            {
            }


            void ConsoleList()
            {
                var files = WordList.GetLists();

                foreach (var file in files)
                {
                    Console.WriteLine(file);
                }
            }

            void ConsoleNew()
            {
                var newFile   = userInput(args)[1];
                var languages = new string[userInput(args).Length - 2];

                if (File.Exists(WordList.GetLists() + newFile + ".dat"))
                {
                    Console.WriteLine($"{newFile} already exists. Try again with a different name.");
                    return;
                }

                for (var i = 0; i < languages.Length; i++)
                {
                    languages[i] = userInput(args)[i + 2];
                }

                currentWordList = new WordList(newFile, languages);
                currentWordList.Save();
                ConsoleAdd();
            }

            void ConsoleAdd()
            {
                currentWordList = WordList.LoadList(userInput(args)[1]);
                if (currentWordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }
                else
                {
                    var word = "";
                    do
                    {
                        var newWord = new string[currentWordList.Languages.Length];

                        for (var i = 0; i < currentWordList.Languages.Length; i++)
                        {
                            Console.Write($"Write a word in {currentWordList.Languages[i]}: ");
                            word = Console.ReadLine();

                            if (word == "")
                            {
                                break;
                            }

                            newWord[i] = word;
                        }

                        if (!newWord.Contains(null))
                        {
                            currentWordList.Add(newWord);
                        }
                    } while (word != "");

                    currentWordList.Save();
                }
            }

            void ConsoleRemove()
            {
                currentWordList = WordList.LoadList(userInput(args)[1]);
                if (currentWordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }
                else
                {
                    var language       = userInput(args)[2];
                    var removeLanguage = 0;

                    for (var i = 0; i < currentWordList.Languages.Length; i++)
                    {
                        if (currentWordList.Languages[i] == language)
                        {
                            removeLanguage = i;
                        }
                    }

                    Console.WriteLine($"The following words were removed from list {userInput(args)[1]}.");
                    for (var i = 3; i < userInput(args).Length; i++)
                    {
                        if (currentWordList.Remove(removeLanguage, userInput(args)[i]))
                        {
                            Console.WriteLine($"- {userInput(args)[i]}");
                        }
                    }

                    currentWordList.Save();
                }
            }

            void ConsoleWords()
            {
                currentWordList = WordList.LoadList(userInput(args)[1]);
                if (currentWordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }
                else
                {
                    var languageToSort    = userInput(args)[2];
                    var numberOfLanguages = 0;

                    for (var i = 0; i < currentWordList.Languages.Length; i++)
                    {
                        if (languageToSort == currentWordList.Languages[i])
                        {
                            numberOfLanguages = i;
                        }
                    }

                    Console.WriteLine();

                    foreach (var t in currentWordList.Languages)
                    {
                        Console.Write($"{t.PadRight(20).ToUpper()}");
                    }

                    Console.WriteLine();

                    Action <string[]> listWords = words =>
                    {
                        foreach (var t in words)
                        {
                            Console.Write($"{t.PadRight(20)}");
                        }

                        Console.WriteLine();
                    };
                    currentWordList.List(numberOfLanguages, listWords);
                    Console.WriteLine();
                }
            }

            void ConsoleCount()
            {
                currentWordList = WordList.LoadList(userInput(args)[1]);
                if (currentWordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }

                else
                {
                    Console.WriteLine($"Number of words in {currentWordList.Name}: {currentWordList.Count()}");
                }
            }

            void ConsolePractice()
            {
                currentWordList = WordList.LoadList(userInput(args)[1]);
                if (currentWordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }
                else
                {
                    var wordTranslation       = "";
                    var attemptedTranslations = 0.0;
                    var accurateTranslations  = 0.0;

                    while (true)
                    {
                        Console.WriteLine();
                        var word = currentWordList.GetWordToPractice();
                        Console.WriteLine(
                            $"Translate {currentWordList.Languages[word.FromLanguage]}: {word.Translations[word.FromLanguage]}");
                        Console.Write($"To {currentWordList.Languages[word.ToLanguage]}: ");
                        wordTranslation = Console.ReadLine();
                        attemptedTranslations++;

                        if (wordTranslation == word.Translations[word.ToLanguage])
                        {
                            Console.WriteLine("Correct translation!");
                            accurateTranslations++;
                        }

                        if (wordTranslation != word.Translations[word.ToLanguage])
                        {
                            if (wordTranslation == "")
                            {
                                attemptedTranslations--;
                                Console.WriteLine();
                                break;
                            }

                            Console.WriteLine("Incorrect translation!");
                        }
                    }

                    if (string.IsNullOrWhiteSpace(wordTranslation))
                    {
                        Console.WriteLine();
                        Console.WriteLine(
                            $"Number of words you practiced: {attemptedTranslations}, Accurate amount of translations: {accurateTranslations}");
                        Console.WriteLine($"Your score: {accurateTranslations / attemptedTranslations * 100:0}%");
                    }
                }
            }
        }
Пример #5
0
        private static void Main(string[] args)
        {
            WordList _wordList = null;

            WordList.CreateFolder();



            if (args.Length == 0)
            {
                Console.WriteLine("Use any of the following parameters : ");
                Console.WriteLine("-lists");
                Console.WriteLine("-new <list name> <language 1> <language 2> ..<language n>");
                Console.WriteLine("-add <list name>");
                Console.WriteLine("-remove <list name > <language> <word1> <word2>... <word n>");
                Console.WriteLine("-words <listname> <sortByLanguage>");
                Console.WriteLine("-count <listname>");
                Console.WriteLine("-practice <listname>");
            }
            else
            {
                switch (Input(args)[0])
                {
                case "-lists":
                    ListCon();

                    break;

                case "-new":

                    try
                    {
                        AddNew();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid add new input, try again!");
                        Console.WriteLine();
                    }
                    break;

                case "-add":
                    try
                    {
                        AddWords();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid add input, try again!");
                        Console.WriteLine();
                    }
                    break;

                case "-remove":
                    try
                    {
                        ConsoleRemove();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid remove input, try again!");
                        Console.WriteLine();
                    }

                    break;

                case "-words":
                    try
                    {
                        ConsoleWords();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid input, try again!");
                        Console.WriteLine();
                    }
                    break;

                case "-count":
                    try
                    {
                        ConsoleCount();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid input, try again!");
                        Console.WriteLine();
                    }
                    break;

                case "-practice":
                    try
                    {
                        ConsolePractice();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid input, try again!");
                        Console.WriteLine();
                    }
                    break;
                }
            }



            void AddWords()
            {
                _wordList = WordList.LoadList(Input(args)[1]);
                if (_wordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }
                else
                {
                    var word = "";
                    do
                    {
                        var newWord = new string[_wordList.Languages.Length];

                        for (var i = 0; i < _wordList.Languages.Length; i++)
                        {
                            Console.Write($"Write a word in {_wordList.Languages[i]}: ");
                            word = Console.ReadLine();

                            if (word == "")
                            {
                                break;
                            }

                            newWord[i] = word;
                        }

                        if (!newWord.Contains(null))
                        {
                            _wordList.Add(newWord);
                        }
                    } while (word != "");

                    _wordList.Save();
                }
            }

            void ListCon()
            {
                string[] lists = WordList.GetLists();
                if (lists.Length > 0)
                {
                    Console.WriteLine("you have this Lists:");
                    Console.WriteLine();

                    foreach (var list in lists)
                    {
                        Console.WriteLine(list);
                    }
                }
                else
                {
                    Console.WriteLine("No lists available, make a new one!");
                }
                var files = WordList.GetLists();

                foreach (var file in files)
                {
                    Console.WriteLine(file);
                }
            }

            void AddNew()
            {
                string name         = Input(args)[1];
                var    languageList = new string[Input(args).Length - 2];

                if (File.Exists(WordList.GetLists() + name + ".dat"))
                {
                    Console.WriteLine($"{name} already exists. Try again with a different name.");
                    return;
                }
                if (args.Length < 3)
                {
                    Console.WriteLine($"The list must have atleast 1 name and 2 languages. ");
                    return;
                }


                for (var i = 0; i < languageList.Length; i++)
                {
                    languageList[i] = Input(args)[i + 2];
                }

                _wordList = new WordList(name, languageList);
                _wordList.Save();
                ConsoleAdd();
            }

            void ConsoleAdd()
            {
                _wordList = WordList.LoadList(Input(args)[1]);
                if (_wordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }
                else
                {
                    var word = "";
                    do
                    {
                        var newWord = new string[_wordList.Languages.Length];

                        for (var i = 0; i < _wordList.Languages.Length; i++)
                        {
                            Console.Write($"Write a word in {_wordList.Languages[i]}: ");
                            word = Console.ReadLine();

                            if (word == "")
                            {
                                break;
                            }

                            newWord[i] = word;
                        }

                        if (!newWord.Contains(null))
                        {
                            _wordList.Add(newWord);
                        }
                    }while (word != "");
                    _wordList.Save();
                }
            }

            void ConsoleRemove()
            {
                _wordList = WordList.LoadList(Input(args)[1]);
                var language   = Input(args)[2];
                var removeLang = 0;

                if (_wordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }
                else
                {
                    for (var i = 0; i < _wordList.Languages.Length; i++)
                    {
                        if (_wordList.Languages[i] == language)
                        {
                            removeLang = i;
                        }
                    }

                    Console.WriteLine($"The words  {Input(args)[1]}  were removed from list.");
                    for (var i = 3; i < Input(args).Length; i++)
                    {
                        if (_wordList.Remove(removeLang, Input(args)[i]))
                        {
                            Console.WriteLine($"- {Input(args)[i]}");
                        }
                    }

                    _wordList.Save();
                }
            }

            void ConsoleWords()
            {
                _wordList = WordList.LoadList(Input(args)[1]);
                var langSort          = Input(args)[2];
                var numberOfLanguages = 0;

                if (_wordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }
                else
                {
                    for (var i = 0; i < _wordList.Languages.Length; i++)
                    {
                        if (langSort == _wordList.Languages[i])
                        {
                            numberOfLanguages = i;
                        }
                    }

                    Console.WriteLine();

                    foreach (var t in _wordList.Languages)
                    {
                        Console.Write($"{t.PadRight(20).ToLower()}");
                    }

                    Console.WriteLine();

                    Action <string[]> listWords = words =>
                    {
                        foreach (var t in words)
                        {
                            Console.Write($"{t.PadRight(20)}");
                        }

                        Console.WriteLine();
                    };
                    _wordList.List(numberOfLanguages, listWords);
                    Console.WriteLine();
                }
            }

            void ConsoleCount()
            {
                _wordList = WordList.LoadList(Input(args)[1]);
                if (_wordList == null)
                {
                    Console.WriteLine("The List is not valid.");
                }
                else
                {
                    Console.WriteLine($"The numbers of words in {_wordList.Name} is: {_wordList.Count()}");
                }
            }

            void ConsolePractice()
            {
                _wordList = WordList.LoadList(Input(args)[1]);
                var input = "";
                var attemptedTranslations = 0.0;
                var correct = 0.0;

                if (_wordList == null)
                {
                    Console.WriteLine("Invalid list.");
                }
                else
                {
                    while (true)
                    {
                        Console.WriteLine();
                        var practiceWord = _wordList.GetWordToPractice();
                        Console.WriteLine($"The language is { _wordList.Languages[practiceWord.FromLanguage]} with the word: {practiceWord.Translations[practiceWord.FromLanguage]}");
                        Console.Write($"what is the translation for {_wordList.Languages[practiceWord.ToLanguage]}: ");
                        input = Console.ReadLine().ToLower();
                        attemptedTranslations++;

                        if (input == practiceWord.Translations[practiceWord.ToLanguage])
                        {
                            Console.WriteLine("Correct!");
                            correct++;
                        }
                        if (input != practiceWord.Translations[practiceWord.ToLanguage])
                        {
                            if (input == "")
                            {
                                attemptedTranslations--;
                                Console.WriteLine();
                                break;
                            }

                            Console.WriteLine("Sorry wrong answer!");
                        }
                    }

                    if (string.IsNullOrWhiteSpace(input))
                    {
                        Console.WriteLine();
                        Console.WriteLine($"Number of words you practiced: {attemptedTranslations}, : You got {correct} words right");
                        Console.WriteLine($"Your score: {correct / attemptedTranslations * 100:0}%");
                    }
                }
            }
        }