Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include "FBullCowGame.h"
- using FText = std::string;
- void PrintIntro();
- void PlayGame();
- FText GetGuess();
- bool AskToPlayAgain();
- FBullCowGame BCGame; // instantiate a new game
- // the entry point for our application
- int main()
- {
- std::cout << BCGame.GetCurrentTry();
- bool bPlayAgain = false;
- do
- {
- PrintIntro();
- PlayGame();
- bPlayAgain = AskToPlayAgain();
- }
- while(bPlayAgain);
- return 0; // exit the application
- }
- void PrintIntro()
- {
- // introduce the game
- constexpr int WORD_LENGTH = 5;
- std::cout << "Welcome to Bulls and Cows, a fun word game.\n";
- std::cout << "Can you guess the " << WORD_LENGTH;
- std::cout << " letter isogram I'm thinking of?\n";
- std::cout << std::endl;
- return;
- }
- void PlayGame()
- {
- BCGame.Reset();
- int MaxTries = BCGame.GetMaxTries();
- std::cout << MaxTries << std::endl;
- // loop for the number of turns asking for guesses
- for (int count = 1; count <= MaxTries; count++)
- {
- FText Guess = GetGuess(); // TODO make loop checking valid
- // submit valid guess to the game
- // print number of bulls and cows
- std::cout << "Your guess was: " << Guess << std::endl;
- std::cout << std::endl;
- }
- // TODO summarise game
- }
- FText GetGuess()
- {
- int CurrentTry = BCGame.GetCurrentTry();
- // get a guess from the player
- std::cout <<"Try " << CurrentTry << ": Enter your guess: ";
- FText Guess = "";
- getline(std::cin, Guess);
- return Guess;
- }
- bool AskToPlayAgain()
- {
- std::cout << "Do you want to play again? (y/n) ";
- FText Response = "";
- getline(std::cin, Response);
- return (Response[0] == 'y') || (Response[0] == 'Y');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement