//2 methods from WordInitializator must be moved here!
        public void GuessLetter()
        {
            Console.WriteLine("Enter your guess: ");
            string supposedCharOrCommand = Console.ReadLine();

            if (supposedCharOrCommand.Length == 1) // the input is a character
            {
                char supposedChar = supposedCharOrCommand[0];
                WordInitializator.InitializationAfterTheGuess(Word, supposedChar);
            }
            else if (supposedCharOrCommand.Equals("help"))
            {
                CommandExecuter.RevealTheNextLetter(Word);
            }
            else if (supposedCharOrCommand.Equals("restart"))
            {
                CommandExecuter.Restart();
            }
            else if (supposedCharOrCommand.Equals("exit"))
            {
                CommandExecuter.Exit();
                return;
            }
            else if (supposedCharOrCommand.Equals("top"))
            {
                CommandExecuter.TopResults();
            }
        }
Exemple #2
0
        public static void InitializationAfterTheGuess(string word, char charSupposed)
        {
            StringBuilder wordInitailized = new StringBuilder();
            int           numberOfTheAppearancesOfTheSupposedChar = 0;

            if (allGuessedLettersOrderedByPositionInTheWord.Contains <char>(charSupposed))
            {
                Console.WriteLine("You have already revelaed the letter {0}", charSupposed);
                return;
            }
            for (int i = 0; i < word.Length; i++)
            {
                if (word[i].Equals(charSupposed))
                {
                    allGuessedLettersOrderedByPositionInTheWord[i] = word[i];
                    numberOfTheAppearancesOfTheSupposedChar++;
                }
            }


            if (numberOfTheAppearancesOfTheSupposedChar == 0)
            {
                Console.WriteLine("Sorry! There are no unrevealed letters {0}", charSupposed);
                num2++;
            }
            else
            {
                Console.WriteLine("Good job! You revealed {0} letters.", numberOfTheAppearancesOfTheSupposedChar);
                num1 += numberOfTheAppearancesOfTheSupposedChar;
            }
            Console.WriteLine();
            if (num1 == word.Length) //check if the word is guessed
            {
                EndOfTheGameInitialization(word);
                CommandExecuter.Restart();
            }
            Console.WriteLine("The secret word is:");
            RevealGuessedLetters(word);
        }
Exemple #3
0
 static void Main(string[] args)
 {
     CommandExecuter.Restart();
 }