Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // plays a single game to completion
- void PlayGame()
- {
- BCGame.Reset();
- int32 MaxTries = BCGame.GetMaxTries();
- // loop for the number of turns asking for guesses while the game is not won
- // and there are still tries remaining
- while (!BCGame.IsGameWon() && BCGame.GetCurrentTry() <= MaxTries)
- {
- FText Guess = GetValidGuess(); // TODO make loop checking valid
- // submit valid guess to the game, and receive counts
- FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess);
- std::cout << "Bulls = " << BullCowCount.Bulls;
- std::cout << ", Cows = " << BullCowCount.Cows << "\n\n";
- }
- PrintGameSummary();
- return;
- }
- // loop continually until the user gives a valid guess
- FText GetValidGuess()
- {
- FText Guess = "";
- EGuessStatus Status = EGuessStatus::Invalid_Status;
- do {
- // get a guess from the player
- int32 CurrentTry = BCGame.GetCurrentTry();
- std::cout << "Try " << CurrentTry << " of " << BCGame.GetMaxTries();
- std::cout << ". Enter your guess: ";
- std::getline(std::cin, Guess);
- // check status and give feedback
- Status = BCGame.CheckGuessValidity(Guess);
- switch (Status) {
- case EGuessStatus::Wrong_Length:
- std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n\n";
- break;
- case EGuessStatus::Not_Isogram:
- std::cout << "Please enter a word without repating letters.\n\n";
- break;
- case EGuessStatus::Not_Lowercase:
- std::cout << "Plese enter all lowercase letters.\n\n";
- break;
- default:
- // assume the guess is valid
- break;
- }
- } while (Status != EGuessStatus::OK); // keep looping until we get no errors
- return Guess;
- }
Add Comment
Please, Sign In to add comment