Guest User

Untitled

a guest
Oct 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // plays a single game to completion
  2. void PlayGame()
  3. {
  4. BCGame.Reset();
  5. int32 MaxTries = BCGame.GetMaxTries();
  6.  
  7. // loop for the number of turns asking for guesses while the game is not won
  8. // and there are still tries remaining
  9. while (!BCGame.IsGameWon() && BCGame.GetCurrentTry() <= MaxTries)
  10. {
  11. FText Guess = GetValidGuess(); // TODO make loop checking valid
  12.  
  13. // submit valid guess to the game, and receive counts
  14. FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess);
  15.  
  16. std::cout << "Bulls = " << BullCowCount.Bulls;
  17. std::cout << ", Cows = " << BullCowCount.Cows << "\n\n";
  18. }
  19.  
  20. PrintGameSummary();
  21. return;
  22. }
  23.  
  24. // loop continually until the user gives a valid guess
  25. FText GetValidGuess()
  26. {
  27. FText Guess = "";
  28. EGuessStatus Status = EGuessStatus::Invalid_Status;
  29. do {
  30. // get a guess from the player
  31. int32 CurrentTry = BCGame.GetCurrentTry();
  32. std::cout << "Try " << CurrentTry << " of " << BCGame.GetMaxTries();
  33. std::cout << ". Enter your guess: ";
  34. std::getline(std::cin, Guess);
  35.  
  36. // check status and give feedback
  37. Status = BCGame.CheckGuessValidity(Guess);
  38. switch (Status) {
  39. case EGuessStatus::Wrong_Length:
  40. std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n\n";
  41. break;
  42. case EGuessStatus::Not_Isogram:
  43. std::cout << "Please enter a word without repating letters.\n\n";
  44. break;
  45. case EGuessStatus::Not_Lowercase:
  46. std::cout << "Plese enter all lowercase letters.\n\n";
  47. break;
  48. default:
  49. // assume the guess is valid
  50. break;
  51. }
  52. } while (Status != EGuessStatus::OK); // keep looping until we get no errors
  53. return Guess;
  54. }
Add Comment
Please, Sign In to add comment