‘’’
#include
#include
#include “FBullCowGame.h”
// 2.49
using FText = std::string;
using int32 = int;
void PrintIntro();
int32 AskForDifficulty();//TODO change word length (and tries)
void PlayGame();
bool AskToPlayAgain();
FText GetValidGuess();
void PrintGameSummary();
// Instantiate a new game
FBullCowGame BCGame;
// entry Point of App
int main()
{
bool bPlayAgain = false;
do
{
PrintIntro();
PlayGame();
PrintGameSummary();
bPlayAgain = AskToPlayAgain();
}
while (bPlayAgain);
std::cout << std::endl;
return 0; // Exit App
}
//Output Welcome & Rules
void PrintIntro()
{
std::cout << "\n\nWelcome to Bulls and Cows. A fun word game.\n";
std::cout << std::endl;
std::cout << "An Isogram is a word (or phrase) with no repeated letters.\n\n";
std::cout << " { \n";
std::cout << " ~~~~~~~~~~^~ ) ( ~^~~~~~~~~~~ \n";
std::cout << " / O O \\ \n";
std::cout << " | BULL @ C COW | \n";
std::cout << " ( ( ) ) \n";
std::cout << " ~~~,~~~~~~~~ ~~~~~~~~~~~~ \\ \n";
std::cout << " | | | | \\ \n";
std::cout << " / / \\ \\ \n";
std::cout << " > > < < \n";
std::cout << " \n";
std::cout << " A Bull is the A Cow is a \n";
std::cout << " right letter in the right letter in the \n";
std::cout << " right place wrong place \n";
std::cout << " \n";
/*std::cout << "Can you guess the " << BCGame.GetHiddenWordLength();
std::cout << " letter isogram I am thinking of? ";
std::cout << "(You have " << BCGame.GetMaxTries() << " tries)\n";
*/ //TODO Move this somewhere
return;
}
int32 AskForDifficulty()
{
int32 Level = 0;
std::cout << "The Difficulty Level will determine how many letters\n";
std::cout << "are in the hidden word, and how many guesses you get\n\n";
std::cout << "What Difficulty would you like (1 - 4)? ";
FText Input = "";
do
{
std::getline(std::cin, Input);
if (!isdigit(Input[0]) || (Input.length() != 1) )
{
std::cout << "Only a single digit please ";
}
else if (std::stoi(Input) < 1 || std::stoi(Input) > 4)
{
std::cout << "between 1 & 4 please ";
}
else
{
Level = std::stoi(Input);
}
} while (Level < 1 || Level > 4);
return Level;
}
//Loop for number of tries
void PlayGame()
{
int32 Difficulty = AskForDifficulty();
BCGame.Reset(Difficulty);
int32 MaxTries = BCGame.GetMaxTries();
// loop asking for guesses while game is NOT won
// and there are still tries available
while( !BCGame.IsGameWon() && BCGame.GetCurrentTry()<= MaxTries)
{
FText Guess = GetValidGuess();
// Submit Valid guess to the game and get counts
FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess);
// Print number of bulls and cows
std::cout << "Bulls = " << BullCowCount.Bulls;
std::cout << ". Cows = " << BullCowCount.Cows << std::endl;
}
return;
}
// Get guess from player and loop until it is valid (isogram, right length etc.)
FText GetValidGuess()
{
FText Guess = “”;
EGuessStatus Status = EGuessStatus::Invalid_Status;
do
{
int32 CurrentTry = BCGame.GetCurrentTry();
std::cout << "\nTry " << CurrentTry << "( / " << BCGame.GetMaxTries() << "). Enter your Guess: ";
std::getline(std::cin, Guess);
Status = BCGame.CheckGuessValidity(Guess);
switch (Status)
{
case EGuessStatus::Not_All_Letters:
std::cout << “Guess must not contain any numbers or special characters\n”;
std::cout << “Please Enter a word\n”;
break;
case EGuessStatus::Not_Lowercase:
std::cout << “Guess must be in Lower Case\n”;
std::cout << “Please Enter a word\n”;
break;
case EGuessStatus::Not_Isogram:
std::cout << “Guess must be an isogram\n”;
std::cout << “Please Enter a word\n”;
break;
case EGuessStatus::Wrong_Length:
std::cout << “Guess must contain " << BCGame.GetHiddenWordLength() << " letters\n”;
std::cout << “Please Enter a " << BCGame.GetHiddenWordLength() << " letter word\n”;
break;
default:
break;
}
} while (Status != EGuessStatus::OK);
return Guess;
}
// How did Player do?
void PrintGameSummary()
{
if (BCGame.IsGameWon())
{
std::cout << “** YOU WON!! ** \n”;
}
else
{
std::cout << “Better Luck Next time :-(\n”;
}
}
// Has the player had enough?
bool AskToPlayAgain()
{
std::cout << "\nDo you want to play again (y / n)? ";
FText Response = “”;
std::getline(std::cin, Response);
return ((Response[0] == ‘y’) || (Response[0] == ‘Y’));
}
’’'
aaarrrggghhh