Ejemplo 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();
            }
        }
Ejemplo n.º 2
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");
                }
            }
        }
Ejemplo n.º 3
0
        ///<summary> Updating frames </summary>
        public static void Update()
        {
            DispalyBoard(0);
            string Character;
            int    AnswerLength = 0;

            while (true)
            {
                Character = Console.ReadLine();
                Character = Character.ToUpper();

                //Checking if the user entered more than one character
                while (Character.Length > 1)
                {
                    DispalyBoard(1);
                    Character = Console.ReadLine();
                    Character = Character.ToUpper();
                }
                //Check if the user entered a character does not exist on the keyboard

                while (!CheckCharacterExist(Character))
                {
                    DispalyBoard(2);
                    Character = Console.ReadLine();
                    Character = Character.ToUpper();

                    if (Character.Length > 1)
                    {
                        break;
                    }
                }

                if (Character.Length > 1)
                {
                    DispalyBoard(1);
                    continue;
                }

                if (CheckAnswer(Character))
                {
                    for (int i = 0; i < Board.Count; i++)
                    {
                        if (Character == Board[i])
                        {
                            Board[i] = " ";
                            break;
                        }
                    }
                    AnswerLength++;
                    DispalyBoard(3);
                }

                else
                {
                    Lives--;
                    DispalyBoard(4);
                }

                if (Lives <= 0)
                {
                    break;
                }

                if (AnswerLength == Word.Length)
                {
                    break;
                }
            }

            ClearFunctions.ClearAll();
            if (Lives <= 0)
            {
                Write.MiddleC("OPS, You Lost :(");
                WaitFunctions.WaitForSeconds(4);
                ClearFunctions.ClearAll();
                WaitFunctions.WaitForSeconds(1);
            }

            else
            {
                for (int i = 0; i < 3; i++)
                {
                    Write.Middle("You Win!");
                    WaitFunctions.WaitForMS(800);
                    ClearFunctions.ClearAll();
                    WaitFunctions.WaitForMS(300);
                }
            }

            HangManMenu.MatchResultMenu();
        }
Ejemplo n.º 4
0
        public static void DispalyBoard(int DisplayingStatue)
        {
            string StringToDisplay = "";

            ClearFunctions.ClearAll();
            Console.WriteLine("Lives : " + Lives);
            //to move the cursor up and down from the center
            //increasing this variable will move the cursor down, decreasing  will move the cursor up
            int VerticalSpace = 0;

            //to move the cursor left and right from the center
            //positive value will move the cursor to the right, nagtive to the left
            //int HorizontalSpace = Keyboard.Length / 2;

            //this is just a variable to declare where to start count the horizontal space
            //the horizontal space depends on the length of the characters in the line
            //this variable will simply change to the value of i(the for loop counter) when then vertical space increase
            int Index = 0;

            while (Index < Board.Count)
            {
                while (Board[Index] != "\n")
                {
                    StringToDisplay += Board[Index];
                    Index++;
                }

                Write.Middle(StringToDisplay, 0, VerticalSpace);
                StringToDisplay = "";
                VerticalSpace++;
                Index++;
            }

            StringToDisplay = "";

            for (int i = 0; i < playerAnswer.Length; i++)
            {
                StringToDisplay += playerAnswer[i] + " ";
            }

            Write.Middle(StringToDisplay, 0, VerticalSpace++);

            switch (DisplayingStatue)
            {
            case 1:
                Console.Write("\nEnter only one character");
                break;

            case 2:
                Console.Write("\nThe character should be in the keyboard shown in the screen");
                break;

            case 3:
                Console.Write("\nCorrect!");
                break;

            case 4:
                Console.Write("\nOPS, Wrong answer");
                break;
            }

            Console.Write("\nEnter A Character : ");
        }