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