예제 #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());
        }
예제 #2
0
 private static void PrintIncorrectCharactersGuessed(MovieTitles movieTitle)
 {
     foreach (var incorrectLetter in movieTitle.IncorrectCharactersGuessed)
     {
         Console.Write(incorrectLetter);
     }
 }
예제 #3
0
 private static void PrintGuessStatus(MovieTitles movieTitle)
 {
     for (int i = 0; i < movieTitle.GuessStatus.Length; i++)
     {
         Console.Write(movieTitle.GuessStatus[i]);
         Console.Write(" ");
     }
 }
예제 #4
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);
 }
예제 #5
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);
        }
예제 #6
0
 private static void DisplayWin(MovieTitles movieTitle, AsciiArt asciiArt)
 {
     DisplayGame(movieTitle, asciiArt);
     Console.WriteLine("\n\nYou Win!\n");
 }