Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include "FBullCowGame.h"
- #include <algorithm>
- using FText = std::string;
- using int32 = int;
- void Intro();
- void Play();
- FText Ask();
- bool Retry();
- FBullCowGame BCGame;
- int32 main()
- {
- bool RetryB = false;
- do {
- Intro();
- Play();
- RetryB = Retry();
- } while (RetryB == true);
- }
- void Play()
- {
- BCGame.Reset();
- int32 MaxChances = BCGame.GetMaxChances();
- while (!BCGame.GameWon() && BCGame.GetCurrentChance() <= MaxChances) { //for (int32 Chance = 1; Chance <= MaxChances; Chance++)
- {
- FText Guess = Ask();
- FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess);
- std::cout << "Bulls = " << BullCowCount.Bulls;
- std::cout << ". Cows = " << BullCowCount.Cows << "." << std::endl;
- // submit valid guess
- std::cout << std::endl;
- std::cout << "You wrote: " << Guess << "!\n";
- std::cout << std::endl;
- }
- }
- }
- FText Ask()
- {
- EWordStatus Status = EWordStatus::Invalid;
- do {
- int32 CurrentChance = BCGame.GetCurrentChance();
- // Get input
- std::cout << "Try " << CurrentChance << ".\n";
- FText Guess = "";
- std::cout << "Input your guess: ";
- std::getline(std::cin, Guess);
- std::transform(Guess.begin(), Guess.end(), Guess.begin(), ::tolower);
- Status = BCGame.GuessCorrect(Guess);
- switch (Status)
- {
- case EWordStatus::WrongLength:
- std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n\n";
- break;
- case EWordStatus::NotIsogram:
- std::cout << "Word must be an Isogram (word without repeating letters!)\n\n";
- break;
- default:
- return Guess;
- }
- } while (Status != EWordStatus::Valid);
- }
- bool Retry()
- {
- std::cout << "Would you like to play again? (Y/N) ";
- FText Response = "";
- std::getline(std::cin, Response);
- std::cout << std::endl;
- return (Response[0] == 'y') || (Response[0] == 'Y');
- }
- void Intro()
- {
- // Introduction
- std::cout << "Welcome to Bulls and Cows! A puzzling word game!\n";
- std::cout << "Can you guess the " << BCGame.GetHiddenWordLength() << " letter Isogram?\n";
- std::cout << std::endl;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement