Exemple #1
0
        private static bool GameLoop()
        {
            string      filePath   = @"movies.txt";
            MovieTitles movieTitle = new MovieTitles(filePath);
            AsciiArt    asciiArt   = new AsciiArt();
            char        userGuess;
            var         endGameFlag = false;

            do
            {
                DisplayGame(movieTitle, asciiArt);

                if (asciiArt.HangmanStatus < 7)
                {
                    Console.WriteLine("\n\nGuess: ");
                    userGuess = ProcessUserGuess(movieTitle, asciiArt);
                    movieTitle.ProcessGuess(userGuess, asciiArt);
                    if (CheckIfWon(movieTitle.GuessStatus))
                    {
                        endGameFlag = true;
                        DisplayWin(movieTitle, asciiArt);
                    }
                }
                else
                {
                    endGameFlag = true;
                    Console.WriteLine("\n\nYou Lose.");
                    Console.WriteLine($"\nThe answer was: {movieTitle.MoviePick}\n");
                }
            } while (!endGameFlag);
            return(AskToPlayAgain());
        }
Exemple #2
0
 private static void DisplayGame(MovieTitles movieTitle, AsciiArt asciiArt)
 {
     Console.Clear();
     // Currently here for easy testing, will be removed
     // Console.WriteLine(movieTitle.MoviePick);
     asciiArt.DrawHangman(asciiArt.HangmanStatus);
     PrintGuessStatus(movieTitle);
     Console.Write("     Incorrect Guesses: ");
     PrintIncorrectCharactersGuessed(movieTitle);
 }
        public void ProcessGuess(char guess, AsciiArt asciiArt)
        {
            var guessCorrect = false;

            for (int i = 0; i < _titleArray.Length; i++)
            {
                if (guess.Equals(_titleArray[i]))
                {
                    _guessStatus[i] = _titleArray[i];
                    guessCorrect    = true;
                }
            }
            if (!guessCorrect)
            {
                asciiArt.IncreaseStatus();
                AddLetterToIncorrectGuessList(guess);
            }
        }
Exemple #4
0
        private static char ProcessUserGuess(MovieTitles movieTitle, AsciiArt asciiArt)
        {
            var  errorFlag = false;
            char rawInput  = ' ';

            do
            {
                try
                {
                    rawInput  = char.Parse(Console.ReadLine().ToUpper());
                    errorFlag = false;
                }
                catch (Exception ex)
                {
                    DisplayGame(movieTitle, asciiArt);
                    Console.WriteLine($"\n\n{ex.Message}");
                    Console.WriteLine("Please just enter a single letter: ");
                    errorFlag = true;
                }
            } while (errorFlag);

            return(rawInput);
        }
Exemple #5
0
 private static void DisplayWin(MovieTitles movieTitle, AsciiArt asciiArt)
 {
     DisplayGame(movieTitle, asciiArt);
     Console.WriteLine("\n\nYou Win!\n");
 }