Пример #1
0
        static void Main(string[] args)
        {

            List<string> dictionary = new List<string>();
            using (StreamReader streamer = File.OpenText(DICTIONARY_FILE))
            {
                while (!streamer.EndOfStream)
                {
                    dictionary.Add(streamer.ReadLine());
                }
            }

            string playAgain = "y";
            while (playAgain.StartsWith("y"))
            {
                Console.WriteLine("Hello Los Altos Hacks! :)");
                Console.WriteLine("Let's play a game...");
                Console.WriteLine();

                Console.WriteLine("What length word do you want to use? ");
                int length = int.Parse(Console.ReadLine());

                Console.WriteLine("How many wrong answers allowed? ");
                int max = int.Parse(Console.ReadLine());
                Console.WriteLine();

                HangmanDirector hangman = new HangmanDirector(dictionary, length, max);

                if (hangman.words().Count == 0)
                {
                    Console.WriteLine("No words of that length is in the dictionary.");
                }
                else
                {
                    PlayGame(hangman);
                    playAgain = ShowResults(hangman);
                }
            }
        }
Пример #2
0
        public static string ShowResults(HangmanDirector hangman)
        {
            var answer = hangman.words().First();
            Console.WriteLine("answer = " + answer);
            if (hangman.guessesLeft() > 0)
            {
                Console.WriteLine("You beat me");
            }
            else
            {
                Console.WriteLine("Sorry, you lose");
            }
            Console.WriteLine("Do you want to play again? (type 'y' to play or enter to exit)");
            return Console.ReadLine();

        }