Esempio n. 1
0
        /// <summary>
        /// Adds a word to the word.txt file
        /// </summary>
        public static void Add()
        {
            Filter();

            while (true)
            {
                ClearFunctions.ClearAll();
                StreamWriter SW;
                StreamReader SR;

                SR = new StreamReader(AppContext.BaseDirectory + "\\words.txt");

                line = SR.ReadLine();
                while (line != null)
                {
                    Console.Write(line + ", ");
                    line = SR.ReadLine();
                }

                SR.Close();
                SW = new StreamWriter(AppContext.BaseDirectory + "\\words.txt", true);

                Console.Write("\nEnter a word to be added(Enter (-) to back) : ");

                /*
                 * var key = Console.ReadKey();
                 * if (key.Key == ConsoleKey.Escape)
                 * {
                 *  SW.Close();
                 *  WordsMenu();
                 *  Console.WriteLine("Error in Addwords Function");//just in case if WordsMenu() didn't execute
                 * }
                 * line = key.KeyChar + Console.ReadLine();
                 */

                line = Console.ReadLine();
                if (line == "-")
                {
                    SW.Close();
                    HangManMenu.WordsMenu();
                    return;
                }
                line = line.ToUpper();
                SW.WriteLine(line);
                SW.Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// display the words
        /// </summary>
        public static void Display()
        {
            Filter();
            StreamReader SR = new StreamReader(AppContext.BaseDirectory + "\\words.txt");

            line = SR.ReadLine();

            if (line == null)
            {
                Console.Write("You Didn't add any words yet");
            }

            while (line != null)
            {
                Console.Write(line + ", ");
                line = SR.ReadLine();
            }

            SR.Close();
            Console.WriteLine("\nPress any button to back");
            var key = Console.ReadKey();

            HangManMenu.WordsMenu();
        }
Esempio n. 3
0
        /// <summary>
        /// Deletes a word from word.txt file
        /// </summary>
        public static void Delete()
        {
            Filter();
            StreamWriter SW;
            StreamReader SR;

            string Path  = AppContext.BaseDirectory + "\\words.txt";
            string Path2 = AppContext.BaseDirectory + "\\words2.txt";

            while (true)
            {
                ClearFunctions.ClearAll();
                var file = File.CreateText(Path2);

                int WordIndex = 0;
                SR = new StreamReader(Path);

                line = SR.ReadLine();
                while (line != null)
                {
                    Console.Write(line + "(" + WordIndex + "), ");
                    line = SR.ReadLine();
                    WordIndex++;
                }

                SR.Close();

                Console.Write("\nEnter word number to be deleted(Enter (-) to back) : ");

                /*var key = Console.ReadKey();
                 * if (key.Key == ConsoleKey.Escape)
                 * {
                 *  file.Close();
                 *  File.Delete(Path2);
                 *  FilterWords();
                 *  WordsMenu();
                 * }
                 * string indexChar = key.KeyChar + Console.ReadLine();
                 */

                string indexChar = Console.ReadLine();
                if (indexChar == "-")
                {
                    file.Close();
                    File.Delete(Path2);
                    Filter();
                    HangManMenu.WordsMenu();
                    return;
                }

                try
                {
                    try
                    {
                        Convert.ToInt32(indexChar);
                    }
                    catch
                    {
                        file.Close();
                        File.Delete(Path2);
                        Filter();
                        Delete();
                    }

                    int WordIndexToDelete = Convert.ToInt32(indexChar);
                    WordIndex = 0;
                    SR        = new StreamReader(Path);

                    line = SR.ReadLine();

                    while (line != null)
                    {
                        if (WordIndex == WordIndexToDelete)
                        {
                            line = SR.ReadLine();
                        }

                        file.WriteLine(line);
                        line = SR.ReadLine();
                        WordIndex++;
                    }

                    file.Close();
                    SR.Close();

                    SR = new StreamReader(Path2);
                    SW = new StreamWriter(Path);

                    line = SR.ReadLine();

                    while (line != null)
                    {
                        SW.WriteLine(line);
                        line = SR.ReadLine();
                    }

                    SR.Close();
                    SW.Close();
                    file.Close();
                    Filter();
                }

                catch
                {
                    Console.WriteLine("error 210");
                }
            }
        }