Advertisement
Guest User

main.cpp

a guest
Sep 20th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include "FBullCowGame.h"
  4.  
  5. using FText = std::string;
  6.  
  7. void PrintIntro();
  8. void PlayGame();
  9. FText GetGuess();
  10. bool AskToPlayAgain();
  11.  
  12. FBullCowGame BCGame; // instantiate a new game
  13.  
  14. // the entry point for our application
  15. int main()
  16. {
  17. std::cout << BCGame.GetCurrentTry();
  18.  
  19. bool bPlayAgain = false;
  20. do
  21. {
  22. PrintIntro();
  23. PlayGame();
  24. bPlayAgain = AskToPlayAgain();
  25. }
  26. while(bPlayAgain);
  27.  
  28. return 0; // exit the application
  29. }
  30.  
  31. void PrintIntro()
  32. {
  33. // introduce the game
  34. constexpr int WORD_LENGTH = 5;
  35. std::cout << "Welcome to Bulls and Cows, a fun word game.\n";
  36. std::cout << "Can you guess the " << WORD_LENGTH;
  37. std::cout << " letter isogram I'm thinking of?\n";
  38. std::cout << std::endl;
  39. return;
  40. }
  41.  
  42. void PlayGame()
  43. {
  44. BCGame.Reset();
  45. int MaxTries = BCGame.GetMaxTries();
  46. std::cout << MaxTries << std::endl;
  47.  
  48. // loop for the number of turns asking for guesses
  49. for (int count = 1; count <= MaxTries; count++)
  50. {
  51. FText Guess = GetGuess(); // TODO make loop checking valid
  52.  
  53. // submit valid guess to the game
  54. // print number of bulls and cows
  55.  
  56. std::cout << "Your guess was: " << Guess << std::endl;
  57. std::cout << std::endl;
  58. }
  59.  
  60. // TODO summarise game
  61. }
  62.  
  63. FText GetGuess()
  64. {
  65. int CurrentTry = BCGame.GetCurrentTry();
  66.  
  67. // get a guess from the player
  68. std::cout <<"Try " << CurrentTry << ": Enter your guess: ";
  69. FText Guess = "";
  70. getline(std::cin, Guess);
  71. return Guess;
  72. }
  73.  
  74. bool AskToPlayAgain()
  75. {
  76. std::cout << "Do you want to play again? (y/n) ";
  77. FText Response = "";
  78. getline(std::cin, Response);
  79. return (Response[0] == 'y') || (Response[0] == 'Y');
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement