Example #1
0
        public static void DisplayGameLost(Player p1, GameLogic game)
        {
            DisplayConsoleUI(p1, game.Asterisks.Count);
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(@"
      

      
                                                  _____                         ____                 
                                                 / ____|                       / __ \                
                                                | |  __  __ _ _ __ ___   ___  | |  | |_   _____ _ __ 
                                                | | |_ |/ _` | '_ ` _ \ / _ \ | |  | \ \ / / _ \ '__|
                                                | |__| | (_| | | | | | |  __/ | |__| |\ V /  __/ |   
                                                 \_____|\__,_|_| |_| |_|\___|  \____/  \_/ \___|_|   
");

            Console.Write(@"
                                                         _____                            __
                                                        / ____|                        _ / /
                                                       | (___   ___  _ __ _ __ _   _  (_) | 
                                                        \___ \ / _ \| '__| '__| | | |   | | 
                                                        __ _) | (_) | |  | |  | |_| |  _| | 
                                                       |_____/ \___/|_|  |_|   \__, | (_) | 
                                                                                __/ |    \_\
                                                                               |___/        
");
            Console.SetCursorPosition(0, 5);
            HangMan.DisplayHangMan(p1);
            DisplayContinuePrompt(62, 27);
            p1.GamesPlayed++;
        }
Example #2
0
        public HangManGame()
        {
            letterGuesses = new List <char>();
            screenPhrases = new List <char[]>();
            gameHeight    = 20;
            gameWidth     = 45;
            man           = new HangMan();
            gameScreen    = new ConsoleManager();
            phraseFinder  = new PhraseMaker();
            player        = new User(gameScreen);
            gameScreen.ConsoleResize(gameHeight, gameWidth);
            stillPlaying   = true;
            alreadyGuessed = false;
            youLost        = youWon = false;

            screenPhrases.Add(new char[] { 'G', 'U', 'E', 'S', 'S', ' ', 'T', 'H', 'E', ' ', 'P', 'H', 'R', 'A', 'S', 'E' });
            screenPhrases.Add(new char[] { 'P', 'R', 'I', 'O', 'R', ' ', 'G', 'U', 'E', 'S', 'S', 'E', 'S' });
            screenPhrases.Add(new char[] { 'A', 'L', 'R', 'E', 'A', 'D', 'Y', ' ', 'T', 'R', 'I', 'E', 'D' });
            screenPhrases.Add(new char[] { 'Y', 'O', 'U', ' ', 'L', 'O', 'S', 'T', '!' });
            screenPhrases.Add(new char[] { 'Y', 'O', 'U', ' ', 'W', 'I', 'N', '!' });
            screenPhrases.Add(new char[] { 'P', 'L', 'A', 'Y', ' ', 'A', 'G', 'A', 'I', 'N', '?' });
        }
Example #3
0
        /// <summary>
        /// Prompts the user for an input, and validates if the input is correct
        /// If it is not, an error message is displayed, and the question is asked again
        /// If the user fails three times to input a valid reponse, the program tells the user
        /// that they have failed too many times and exits the application to prevent infinite looping
        /// </summary>
        /// <param name="prompt">Prompt to display to the user</param>
        /// <param name="p1">Player Object that tracks player progress</param>
        /// <param name="asterisks">List<char> that tracks the progress of the word being guessed</param>
        /// <returns>Returns a char of the validated user input</returns>
        public static char ValidateUserGuess(string prompt, Player p1, List <char> asterisks)
        {
            bool      IsValid           = false;
            const int MAX_TRIES         = 3;
            int       attemptsMade      = 1;
            char      validatedResponse = '?';

            Console.CursorVisible = true;
            while (!IsValid)
            {
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Red;
                HangMan.DisplayHangMan(p1);
                Console.ForegroundColor = ConsoleColor.White;
                Console.SetCursorPosition(62, 19);
                Console.Write(prompt);
                Console.ForegroundColor = ConsoleColor.Green;
                string userResponse = Console.ReadLine().Trim().ToLower();

                if (userResponse.Length > 1)
                {
                    IsValid = false;
                }
                else
                {
                    IsValid = Regex.IsMatch(userResponse, @"(?i)^[a-z]{1}");
                }

                try
                {
                    Char.IsLetter(Convert.ToChar(userResponse));
                    validatedResponse = Convert.ToChar(userResponse);
                }
                catch (Exception)
                {
                    Console.SetCursorPosition(62, 20);
                    Console.WriteLine("ERROR: Input must be exactly one character!");
                }

                if (!IsValid)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition(62, 21);
                    Console.WriteLine("Sorry, you did not input a valid character.");
                    DisplayContinuePrompt();
                    attemptsMade++;
                    DisplayMainScreen(asterisks, p1);
                    DisplayMiddleBar();
                }

                if (attemptsMade > MAX_TRIES)
                {
                    DisplayConsoleUI(p1, asterisks.Count);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write(@"
  

          ______    _ _          _   _                                              _   _                     
         |  ____|  (_) |        | | | |                                            | | (_)                    
         | |__ __ _ _| | ___  __| | | |_ ___   ___    _ __ ___   __ _ _ __  _   _  | |_ _ _ __ ___   ___  ___ 
         |  __/ _` | | |/ _ \/ _` | | __/ _ \ / _ \  | '_ ` _ \ / _` | '_ \| | | | | __| | '_ ` _ \ / _ \/ __|
         | | | (_| | | |  __/ (_| | | || (_) | (_) | | | | | | | (_| | | | | |_| | | |_| | | | | | |  __/\__ \
         |_|  \__,_|_|_|\___|\__,_|  \__\___/ \___/  |_| |_| |_|\__,_|_| |_|\__, |  \__|_|_| |_| |_|\___||___/
                                                                             __/ |                            
                                                                            |___/                             
             ______      _ _   _               _   _            _____                                     
            |  ____|    (_) | (_)             | | | |          |  __ \                                    
            | |__  __  ___| |_ _ _ __   __ _  | |_| |__   ___  | |__) | __ ___   __ _ _ __ __ _ _ __ ___  
            |  __| \ \/ / | __| | '_ \ / _` | | __| '_ \ / _ \ |  ___/ '__/ _ \ / _` | '__/ _` | '_ ` _ \ 
            | |____ >  <| | |_| | | | | (_| | | |_| | | |  __/ | |   | | | (_) | (_| | | | (_| | | | | | |
            |______/_/\_\_|\__|_|_| |_|\__, |  \__|_| |_|\___| |_|   |_|  \___/ \__, |_|  \__,_|_| |_| |_|
                                        __/ |                                    __/ |                    
                                       |___/                                    |___/                     


");
                    DisplayContinuePrompt(2, 27);
                    Quit();
                }
            }
            return(validatedResponse);
        }
Example #4
0
 public void ShowGameState(Computer computer)
 {
     HangMan.Draw(computer.wrongGuessesMade);
 }