Guest User

Untitled

a guest
Nov 15th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include "FBullCowGame.h"
  6.  
  7. // to make syntax Unreal friendly
  8. using FText = std::string;
  9. using int32 = int;
  10.  
  11. // function prototypes as outside a class
  12. void PrintIntro();
  13. void PlayGame();
  14. FText GetValidGuess();
  15. bool AskToPlayAgain();
  16. void PrintGameSummary();
  17. int32 WordSelector();
  18.  
  19. FBullCowGame BCGame; // instantiate a new game, which we re-use across plays
  20. int32 Answer;
  21. // the entry point for our application
  22. int main()
  23. {
  24. do
  25. {
  26. PrintIntro();
  27. PlayGame();
  28. }
  29. while (AskToPlayAgain() == true);
  30.  
  31. return 0; // exit the application
  32. }
  33.  
  34. void PrintIntro()
  35. {
  36. std::cout << "Welcome to Bulls and Cows, a fun word game.\n";
  37. std::cout << std::endl;
  38. std::cout << " } { ___ " << std::endl;
  39. std::cout << " (o o) (o o) " << std::endl;
  40. std::cout << " /-------\\ / \\ /-------\\ " << std::endl;
  41. std::cout << " / | BULL |O O| COW | \\ " << std::endl;
  42. std::cout << " * |-,--- | |------| * " << std::endl;
  43. std::cout << " ^ ^ ^ ^ " << std::endl;
  44. Answer = WordSelector();
  45. FWordSelection WordSelected = BCGame.WordSelection(Answer);
  46. std::cout << "Can you guess the " << BCGame.GetHiddenWordLength();
  47. std::cout << " letter isogram I'm thinking of?\n";
  48. std::cout << std::endl;
  49. return;
  50. }
  51.  
  52. // plays a single game to completion
  53. void PlayGame()
  54. {
  55. BCGame.Reset();
  56. int32 MaxTries = BCGame.GetMaxTries();
  57.  
  58. // loop asking for guesses while the game
  59. // is NOT won and there are still tries remaining
  60. while (!BCGame.IsGameWon() && BCGame.GetCurrentTry() < MaxTries) {
  61. FText Guess = GetValidGuess();
  62.  
  63. // submit valid guess to the game, and receive counts
  64. FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess);
  65.  
  66. std::cout << "Bulls = " << BullCowCount.Bulls;
  67. std::cout << ". Cows = " << BullCowCount.Cows << "\n\n";
  68. }
  69.  
  70. PrintGameSummary();
  71. return;
  72. }
  73.  
  74. // loop continually until the user gives a valid guess
  75. FText GetValidGuess()
  76. {
  77. FText Guess = "";
  78. EGuessStatus Status = EGuessStatus::Invalid_Status;
  79. do {
  80. // get a guess from the player
  81. int32 CurrentTry = BCGame.GetCurrentTry();
  82. std::cout << "Try " << CurrentTry << " of " << BCGame.GetMaxTries();
  83. std::cout << ". Enter your guess: ";
  84. std::getline(std::cin, Guess);
  85.  
  86. // check status and give feedback
  87. Status = BCGame.CheckGuessValidity(Guess);
  88. switch (Status) {
  89. case EGuessStatus::Wrong_Length:
  90. std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n\n";
  91. break;
  92. case EGuessStatus::Not_Isogram:
  93. std::cout << "Please enter a word witout repeating letters.\n\n";
  94. break;
  95. case EGuessStatus::Not_Lowercase:
  96. std::cout << "Please enter all lowercase letters.\n\n";
  97. break;
  98. default:
  99. // assume the guess is valid
  100. break;
  101. }
  102. } while (Status != EGuessStatus::OK);
  103. return Guess;
  104. }
  105.  
  106. bool AskToPlayAgain()
  107. {
  108. std::cout << "Do you want to play again with the same hidden word (y/n)? ";
  109. FText Response = "";
  110. std::getline(std::cin, Response);
  111. return (Response[0] == 'y') || (Response[0] == 'Y');
  112. }
  113.  
  114. void PrintGameSummary()
  115. {
  116. if (BCGame.IsGameWon())
  117. {
  118. std::cout << "WELL DONE - YOU WIN!\n";
  119. }
  120. else
  121. {
  122. std::cout << "Better luck next time!\n";
  123. }
  124. }
  125.  
  126. int32 WordSelector()
  127. {
  128. std::cout << "How many letter word do you want?(3/4/5)" << std::endl;
  129. Answer;
  130. std::cin >> Answer;
  131. return Answer;
Add Comment
Please, Sign In to add comment