Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 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 Guess;
  10. FText GetGuess();
  11. bool AskToPlayAgain(); //also puts a bool to the console for later use
  12.  
  13. FBullCowGame BCGame;
  14.  
  15. int main()
  16. {
  17.     bool bPlayAgain = false;
  18.     do {
  19.         PrintIntro();
  20.         PlayGame();
  21.         bPlayAgain = AskToPlayAgain();
  22.         }
  23.     while (bPlayAgain);
  24.  
  25.         return 0; //exit the program
  26. }
  27.  
  28. void PlayGame()
  29. {
  30.     int MyCurrentTry = BCGame.GetCurrentTry();
  31.     int MaxTries = BCGame.GetMaxTries();
  32.     std::cout << MaxTries << std::endl;
  33.  
  34.     constexpr int Number_Of_Turns = 5;
  35.  
  36.     //TODO change from FOR to WHILE loop when we are validating guesses
  37.     for (int count = 1; count <= MaxTries; count++)
  38.     {
  39.         std::cout << "This will be guess #" << MyCurrentTry << std::endl;
  40.         FText Guess = GetGuess(); //TODO make loop to check guess validity
  41.  
  42.         //submit valid guess to the game
  43.         //pring number of bulls and cows
  44.  
  45.         std::cout << "Your guess was: " << Guess << std::endl;
  46.         std::cout << std::endl;
  47.         MyCurrentTry++;
  48.         //TODO add a game summary
  49.         //Print out the number of remaining guesses
  50.     }
  51. }
  52.  
  53. //get a guess from the user
  54. FText GetGuess()
  55. {
  56.     std::cout << "Please enter your guess: ";
  57.     FText Guess = "";
  58.     getline(std::cin, Guess);
  59.     return Guess;
  60. }
  61.  
  62. bool AskToPlayAgain()
  63. {
  64.     std::cout << "Do you want to play again? (y/n)? ";
  65.     FText Response = "";
  66.     getline(std::cin, Response);
  67.     return (Response[0] == 'y') || (Response[0] == 'Y');
  68. }
  69.  
  70. //introduce the game
  71. void PrintIntro()
  72. {
  73.     constexpr int WORD_LENGTH = 5;
  74.     std::cout << "Welcome to Bulls and Cows, a word game!\n";
  75.     std::cout << "Can you guess the ";
  76.     std::cout << WORD_LENGTH;
  77.     std::cout << " letter isogram I'm thinking of?\n";
  78.     std::cout << std::endl;
  79.     return;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement