//play the game void PlayGame() { BCGame.Reset(); int32 MaxTries = BCGame.GetMaxTries(); //loop asking for guess while //game is NOT won and their are still tries remainging while(!BCGame.IsGameWon() && BCGame.GetCurrentTry() <= MaxTries) { FText Guess = GetValidGuess(); //submit a valid guess to game FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess); std::cout << "Bull = " << BullCowCount.Bulls; std::cout << ". Cows = " << BullCowCount.Cows; std::cout << std::endl; } PrintGameSummary(); return; }
std::string GetGuess() { FText Guess = ""; EGuessStatus Status = EGuessStatus::Invalid; do { int CurrentTry = BCGame.GetCurrentTry(); //get a guess from player std::cout << "Try " << CurrentTry << " of " << BCGame.GetMaxTries(); std::cout << ". Enter your guess: "; std::getline (std::cin, Guess); Status = BCGame.CheckGuessValidity(Guess); switch (Status) { case EGuessStatus::Wrong_Length: std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n\n"; break; case EGuessStatus::Not_Lowercase: std::cout << "Please enter a lowercase word.\n\n"; break; case EGuessStatus::Not_Isogram: std::cout <<"Please enter a word without repeating letters.\n\n"; break; default: break; } } while (Status != EGuessStatus::OK); //keep looping until we get valid input return Guess; }
// loop continually until the user gives a valid guess FText GetValidGuess() { FText Guess = ""; EGuessStatus Status = EGuessStatus::Invalid_Status; do { // get a guess from the player int32 TryNumber = BCGame.GetCurrentTry(); std::cout << "Try " << TryNumber << " of " << BCGame.GetMaxTries(); std::cout << ". Enter your guess: "; std::getline(std::cin, Guess); Status = BCGame.CheckGuessValidity(Guess); switch (Status){ case EGuessStatus::Wrong_Length: std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word. \n\n"; break; case EGuessStatus::Not_Isogram: std::cout << "Please enter a word without repeating letters.\n\n"; break; case EGuessStatus::Not_Lowercase: std::cout << "Please enter all lowercase letters.\n\n"; break; default: break; } std::cout << std::endl; } while (Status != EGuessStatus::OK); // keep looking until we get no errors return Guess; }
//get the guess and print it back to you FText GetValidGuess() { FText Guess; EGuessStatus Status = EGuessStatus::Invalid_Status; do { int32 CurrentTry = BCGame.GetCurrentTry(); std::cout << "Try " << CurrentTry++ << " of "<< BCGame.GetMaxTries()<<". Take a swag: "; std::getline(std::cin, Guess); Status = BCGame.CheckGuessValidity(Guess); switch (Status) { case EGuessStatus::Wrong_Length: std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n\n"; break; case EGuessStatus::Not_Isogram: std::cout << "Make sure you have entered a word without repeating letters.\n\n"; break; case EGuessStatus::Not_Lowercase: std::cout << "Please enter an all-lowercase word.\n\n"; break; default: //assume the guess is valid break; } } while (Status != EGuessStatus::OK); //keep looping until we get no errors return Guess; }
//get a guess from the user FText GetValidGuess() { EGuessStatus Status = EGuessStatus::Invalid; FText Guess = ""; do { int32 CurrentTry = BCGame.GetCurrentTry(); std::cout << "Try " << CurrentTry << " of " << BCGame.GetMaxTries() << ". Enter your guess: "; std::getline(std::cin, Guess); Status = BCGame.CheckGuessValidity(Guess); switch (Status) { case EGuessStatus::Wrong_Length: std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n"; break; case EGuessStatus::Not_Isogram: std::cout << "Please enter a word without repeating letters.\n"; break; case EGuessStatus::Not_Lowercase: std::cout << "Please enter the word using all lowercase letters.\n"; break; default: break; // Assume guess is valid } std::cout << std::endl; } while (Status != EGuessStatus::OK); // keep looping until we get no errors return Guess; }
// loop continually until user gives a valid guess. FText GetGuess() { FText InString; EGuessStatus Status = EGuessStatus::Invalid_Status; int32 CurrentTry = BCGame.GetCurrentTry(); do { std::cout << "Try #" << CurrentTry << "/" << BCGame.GetMaxTries() << " Enter your guess: "; getline(std::cin, InString); Status = BCGame.GuessValid(InString); switch (Status) { case EGuessStatus::Wrong_Length: std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n\n"; break; case EGuessStatus::Not_Isogram: std::cout << "Please enter a word without repeating letters.\n\n"; break; case EGuessStatus::Not_Lowercase: std::cout << "Please ensure that your input is all lowercase letters.\n\n"; break; default: return InString; } } while (Status != EGuessStatus::OK); return InString; }
void PlayGame(){ int32 MaxTries = BCGame.GetMaxTries(); std::cout << MaxTries << std::endl; //BCGame() = FBullCowGame(); // loop for the number of turns asking for entries //constexpr int NUMBER_OF_TURNS = 5; //TODO: Change from For to a While loop once we are validating tries while (BCGame.IsGameWon()==false && BCGame.GetCurrentTry() <= MaxTries) { //std::cout<< "Status of Game is : " <<BCGame.IsGameWon() << "\n\n"; //for (int32 count = 1; count <= MaxTries; count++) { FText Guess = GetValidGuess(); //TODO: Make check for valid guesses. // Submit valid guess to the game FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess); // Print number of bulls and cows std::cout << "Bulls = " << BullCowCount.Bulls << " \n"; std::cout << "Cows = " << BullCowCount.Cows << " \n"; std::cout << "You entered >> " << Guess << " <<, thank you, let me check.\n"; std::cout << std::endl; //std::cout<< "Status of Game is : inside FOR Loop " <<BCGame.IsGameWon() << "\n\n"; } PrintGameSummary(); return; //TODO: HELLO }
// Get a guess from the player FText GetValidGuess() { EGuessStatus Status = EGuessStatus::Invalid; do { int32 CurrentTry = BCGame.GetCurrentTry(); std::cout << "Try "<< CurrentTry << ": Enter your guess here: "; FText GetGuessVal=""; std::getline(std::cin, GetGuessVal); //CurrentTry++; Status = BCGame.CheckGuessValidity(GetGuessVal); switch (Status) { case EGuessStatus::Wrong_Length: std::cout << "please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n"; break; case EGuessStatus::Not_Isogram: std::cout << "please enter a word without repeating letters.\n"; break; case EGuessStatus::Not_Lowercase: std::cout << "please enter a word in lower case.\n"; break; default: return GetGuessVal; } } while (Status != EGuessStatus::OK); //Keep looping until we get a valid entry return 0; }
void SetDifficulty() { FText InString; getline(std::cin, InString); try { int Level = std::stoi(InString); if (Level < 1 || Level > 5) { std::cout << "\nPlease be sure to enter a valid integer between 1 and 5: "; SetDifficulty(); } else { BCGame.SetDifficulty(Level); std::cout << std::endl << "Alright, we're working with a " << BCGame.GetHiddenWordLength() << " letter isogram. Let's play the game!\n\n"; } } catch (std::invalid_argument& e) { std::cout << "\nPlease be sure to enter a valid integer between 1 and 5: "; SetDifficulty(); } catch (std::out_of_range& e) { std::cout << "\nPlease be sure to enter a valid integer between 1 and 5: "; SetDifficulty(); } }
void PlayGame() { int32 MaxTries = BCGame.GetMaxTries(); // Get a guess from the player and repeat it back to them. while(!BCGame.IsGameWon() && BCGame.GetCurrentTry() <= MaxTries) { FText Input = GetGuess(); FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Input); std::cout << "Number of Bulls: " << BullCowCount.Bulls << std::endl; std::cout << "Number of Cows: " << BullCowCount.Cows << std::endl << std::endl; } PrintGameSummary(BCGame.IsGameWon()); return; }
// Plays a single game to completion void PlayGame() { BCGame.Reset(); int32 MaxTries = BCGame.GetMaxTries(); //Loop asking for guesses while the game is NOT won and there are still turns while (!BCGame.IsGameWon() && BCGame.GetCurrentTry() <= MaxTries) { FText Guess = GetValidGuess(); FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess); std::cout << "Bulls = " << BullCowCount.Bulls; std::cout << ", Cows = " << BullCowCount.Cows << "\n\n"; } PrintGameSummary(); }
// Get a guess from the player FText GetGuess() { FText Guess = ""; std::cout << BCGame.GetCurrentTry() << ". Make a guess: "; //BCGame.IncTry(); getline(std::cin, Guess); return Guess; }
// Introduce the game void PrintIntro(){ std::cout << ("\n\nHELLO\n"); std::cout << ("This is using namespace identifiers\n"); std::cout << ("Welcome to Bull and Cows a Fun Game\n"); std::cout << "Can you guess the "<< BCGame.GetHiddenWordLength() <<" letter isogram I'm thinking of?\n"; return; }
FText GetGuess() { FText Guess = ""; std::cout << "Try " << BCGame.GetCurrentTry() << ": Enter your guess: "; std::getline(std::cin, Guess); return Guess; }
void PrintGameSummary(){ if (BCGame.IsGameWon()){ std::cout << "Well Done - YOU WIN!\n"; } else{ std::cout << "Better luck next time !\n"; } }
// plays a single game to completion void PlayGame() { BCGame.Reset(); int32 MaxTries = BCGame.GetMaxTries(); // loop asking for guesses while the game // is NOT won and there are still tries remaining while(!BCGame.IsGameWon() && BCGame.GetCurrentTry() <= MaxTries) { FText Guess = GetValidGuess(); // submit valid guess to the game, and receive counts FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess); PrintGuess(BullCowCount); } return; }
void PrintIntro() { //introduction std::cout << "\nWelcome to Bulls and Cows, a fun word game\n"; std::cout << "Can you guess the " << BCGame.GetHiddenWordLength(); std::cout << " letter isogram I'm thinking of?\n"; std::cout << std::endl; return; }
// plays a single game to completion void PlayGame() { BCGame.Reset(); int32 MaxTries = BCGame.GetMaxTries(); while (!BCGame.IsGameWon() && BCGame.GetCurrentTry() <= MaxTries) { FText Guess = GetValidGuess(); // submit valid guess to the game, and receive counts FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess); std::cout << "Bulls = " << BullCowCount.Bulls; std::cout << ". Cows = " << BullCowCount.Cows << "\n\n"; } PrintGameSummary(); return; }
void PrintGameSummmary() { if (!BCGame.IsGameWon()) { std::cout << "Sorry, you weren't able to figure out the isogram in the specified number of tries.\nBetter luck next time!\n\n"; } else { std::cout << "Congratulations you won!\n\n"; } }
void PrintGameSummary() { if (BCGame.IsGameWon() == true) { std::cout << "WELL DONE - YOU WIN!" << std::endl; } else { std::cout << "Better luck next time!" << std::endl; } }
//declaration of function PrintIntro void PrintIntro() { //introduce the game int32 WORD_LENGTH = BCGame.GetHiddenWordLength(); std::cout << "Welcome to Bulls and Cows :) "; std::cout << std::endl; std::cout << "Can you guess this " << WORD_LENGTH << " letter word, i'm thinking of?\n"; std::cout << std::endl; return; }
void PrintIntro() { int32 WORD_LENGTH = BCGame.GetHiddenWordLength(); std::cout << "\n\n|||||/--------------------------------------------------------------\\|||||\n"; std::cout << "||||/----------------------------------------------------------------\\||||\n"; std::cout << "||||| Welcome to Bulls and Cows, a fun word game. |||||\n"; std::cout << "||||| Can you get the " << WORD_LENGTH << " letter isogram that I'm thinking of? |||||\n"; std::cout << "||||\\----------------------------------------------------------------/||||\n"; std::cout << "|||||\\--------------------------------------------------------------/|||||\n\n"; return; }
void PrintGameSummary() { if (BCGame.IsGameWon()) { std::cout << "Congratulations, you won!! \n"; } else { std::cout << "Sorry, you lose! \n"; } }
// plays a single game to completion void PlayGame() { BCGame.Reset(); int32 MaxTries = BCGame.GetMaxTries(); // loop asking for guesses while the game // is NOT won and there are still tries remaining while (!BCGame.IsGameWon() && BCGame.GetCurrentTry() <= MaxTries) { FText Guess = GetValidGuess(); // submit valid guess to the game, and receive counts FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess); std::cout << "Bulls = " << BullCowCount.Bulls; std::cout << ". Cows = " << BullCowCount.Cows << "\n\n"; } PrintGameSummary(); return; }
void PlayGame() { BCGame.Reset(); int MaxTries = BCGame.GetMaxTries(); //loop asking for guesses while the game is NOT won while (!BCGame.IsGameWon() && BCGame.GetCurrentTry() <= MaxTries) { FText Guess = GetGuess(); //submit valid guess to game FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess); //print number of bulls and cows std::cout << "Bulls = " << BullCowCount.Bulls; std::cout << " Cows = " << BullCowCount.Cows << "\n\n"; std::cout << "Your guess was: " << Guess << std::endl; std::cout << std::endl; } PrintGameSummary(); return; }
void PrintGameSummary() { if (BCGame.IsGameWon()) { std::cout << "Hurraaah ! You won the Game !\n"; } else { std::cout << "Opps ! Better luck next time !\n"; } return; }
void PlayGame(){ BCGame.Reset(); PrintIntro(); // Loop for the number of turns asking for guesses for (int32 count = 1; count <= BCGame.GetMaxTries(); count++) { FText guess = GetGuess(); EWordStatus status = BCGame.CheckGuessValidity(guess); switch (status) { case EWordStatus::OK: { FBullCowCount bullCowCount = BCGame.SubmitGuess(guess); // print the number of bulls and cows std::cout << "Bulls " << bullCowCount.Bulls; std::cout << " Cows " << bullCowCount.Cows; std::cout << std::endl; break; } case EWordStatus::Wrong_Length: { std::cout << "Wrong length! Try again.\n"; break; } case EWordStatus::Not_Lowercase : { std::cout << "Not Lowercase! Try again.\n"; break; } default: { std::cout << "Not Valid! Try again.\n"; break; } } if (status == EWordStatus::OK) { } } return; }
int main(int32 argc, const char * argv[]) { // Do - While loop bool bPlayAgain = false; do { BCGame.Reset(); PrintIntro(); // form of abstraction PlayGame(); bPlayAgain = AskToPlayAgain(); } while(bPlayAgain); return 0; //TODO: Hello world }
//get Valid guess from user FText GetValidGuess() { FText Guess = ""; EGuessStatus Status = EGuessStatus::Invalid_Status; do { //get a guess from player int32 CurrentTry = BCGame.GetCurrentTry(); std::cout << "Try " << CurrentTry <<" of " <<BCGame.GetMaxTries() << ".Enter your Guess:"; std::getline(std::cin, Guess); //checking if the guess is valid Status = BCGame.IsGuessValid(Guess); switch (Status) { case EGuessStatus::Not_Isogram: std::cout << "Please Enter a word without repeating letters !" << std::endl; break; case EGuessStatus::Lower_Case: std::cout << "Please Enter all lower case letters !" << std::endl; break; case EGuessStatus::Wrong_Lenght: std::cout << "Please Enter a " << BCGame.GetHiddenWordLength() << " letter Word !" << std::endl; break; default: //Assume that the status is OK break; } std::cout << std::endl; } while (Status != EGuessStatus::OK); //keep looping until we get no errors or we get Status == OK return Guess; }
void PlayGame() { BCGame.Reset(); int32 MaxTries = BCGame.GetMaxTries(); //Loop for the number of turns asking for guesses //TODO change from for to while loop for (int32 count = 0; count < MaxTries; count++) { FText Guess = GetGuess(); //TODO make loop checking valid //Submit valid guess to the game FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess); //Print number of bulls and cows std::cout << "Bulls = " << BullCowCount.Bulls; std::cout << "Cows = " << BullCowCount.Cows; std::cout << std::endl; } //TODO summarise game }