Advertisement
Guest User

main.cpp

a guest
Nov 15th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include "FBullCowGame.h"
  5.  
  6. using int32 = int;
  7. using FText = std::string;
  8.  
  9. void PrintIntro();
  10. void PlayGame();
  11. bool AskToPlayAgain();
  12. FText GetGuess();
  13. FBullCowGame BCGame;
  14.  
  15.  
  16.  
  17. int main ()
  18. {
  19. bool bPlayAgain = false;
  20. do
  21. {
  22. PrintIntro();
  23. PlayGame();
  24. bPlayAgain = AskToPlayAgain();
  25. } while (bPlayAgain == true);
  26. system("Pause");
  27. return 0;
  28. }
  29.  
  30.  
  31. void PrintIntro()
  32. {
  33. //introduces the game
  34. std::cout << "Welcome to Bulls and Cow, a fun word game" << std::endl;
  35. std::cout << "Can you guess the " << BCGame.GetHiddenWordLength();
  36. std::cout << " letter isogram I'm thinking off?" << std::endl;
  37. return;
  38. }
  39.  
  40. void PlayGame()
  41. {
  42. BCGame.Reset();
  43. int32 MaxTries = BCGame.GetMaxTries();
  44. std::cout << "You have " << MaxTries << " max tries."<< std::endl;
  45. for (int32 count = 1; count <= MaxTries; count++)
  46. {
  47. FText Guess = GetGuess();
  48.  
  49. FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess);
  50.  
  51. std::cout << "Bulls = " << BullCowCount.Bulls << "." << std::endl;
  52. std::cout << "Cows = " << BullCowCount.Cows << "." << std::endl;
  53. }
  54. }
  55.  
  56. FText GetGuess()
  57. {
  58. //get the guess from the player
  59. int32 CurrentTry = BCGame.GetCurrentTries();
  60. std::cout << "Try " << CurrentTry << "." << std::endl;
  61. FText Guess = "";
  62. std::cout << "Enter your guess: ";
  63.  
  64. std::getline(std::cin, Guess);
  65. return Guess;
  66. }
  67.  
  68. bool AskToPlayAgain()
  69. {
  70. bool status = false;
  71. std::cout << "Do you want to play again?(y/n)" << std::endl;
  72. FText response = "";
  73. std::getline(std::cin, response);
  74. if (response [0] == 'y' || response [0] == 'Y')
  75. {
  76. status = true;
  77. }
  78. return status;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement