示例#1
0
        public static void Start()
        {
            random = new Random();
            int RandomWordIndex = random.Next(0, Words.NumberOfWords());

            if (Words.NumberOfWords() <= 0)
            {
                Write.MiddleC("You need to add words first");
                WaitFunctions.WaitForSeconds(3);
                HangManMenu.ChooseLevelMenu();
                return;
            }

            Lives        = 3;
            Board        = new List <string>();
            Word         = Words.GetWord(RandomWordIndex);
            playerAnswer = new string[Word.Length];

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

            SetKeyBoard(Word);
            SetBoard();

            Update();
        }
示例#2
0
        /// <summary> Starts the Game </summary>
        public static void Awake()
        {
            Console.CursorVisible = false;

            FileStream file;

            if (!File.Exists(Words.Path))
            {
                file = new FileStream(Words.Path, FileMode.Create);
                file.Close();
            }

            HangManMenu.Awake();
        }
示例#3
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();
            }
        }
示例#4
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();
        }
示例#5
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");
                }
            }
        }
示例#6
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();
        }