I'm trying to follow a C++ class to get more acquainted with the language and Unreal Engine. However, now whenever I start the program, the console window immediately closes. I've already tried fixing the subsystem stuff and I've seen some dirty code that wouldn't close the window, but I'd like to know how to get the problem fixed without trying to find a weird circumnavigation.
/* This is the console executable, that makes use of the BullCowClass
This acts as the view in a MVC pattern, and is responsible for all
user interaction. For game logic see the FBullCow`enter code here`Game class.
*/
#include <iostream>
#include <string>
#include "FBullCowGame.h"
using FText = std::string;
using int32 = int;
void PrintIntro();
void PlayGame();
FText GetValidGuess();
bool AskToPlayAgain();
FBullCowGame BCGame; //instantiatiate a new game
// entry point for our application
int main()
{
bool bPlayAgain = false;
do
{
PrintIntro();
PlayGame();
bPlayAgain = AskToPlayAgain();
} while (bPlayAgain == true);
return 0;
}
void PrintIntro()
{
//introduce to game
std::cout << "Welcome to Bulls and Cows" << std::endl;
std::cout << "Can you guess the " << BCGame.GetHiddenWordLength() << " letter isogram I'm thinking of?\n";
std::cout << std::endl;
return;
}
void PlayGame()
{
BCGame.Reset();
int32 MaxTries = BCGame.GetMaxTries();
//looping for the numbert of turns asking for guesses
for (int32 i = 1; i <= MaxTries; i++) {// TODO change from FOR to WHILE
FText Guess = GetValidGuess();
// submit valid guess to the game and receive counts
FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess);
std::cout << "Bulls = " << BullCowCount.Bulls;
std::cout << ". Cows = " << BullCowCount.Cows << "." << "\n\n";
}
// TODO summarize game here
}
//loop continually until the use gives a valid guess
FText GetValidGuess() // TODO change to GetValidGuess
{
EGuessStatus Status = EGuessStatus::Invalid_Status;
do {
//get a guess from the player
int32 CurrentTry = BCGame.GetCurrentTry();
std::cout << "Try " << CurrentTry << " What is your word guess: ";
FText 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 an isogram.\n";
break;
case EGuessStatus::Not_Lowercase:
std::cout << "Please enter your guess in lowercase letters.\n";
break;
default:
return Guess;
}
std::cout << std::endl;
{
};
} while (Status != EGuessStatus::OK); //keep looping until we get no errors
}
bool AskToPlayAgain()
{
std::cout << "Do you want to play again(y/n)? ";
FText Response = "";
std::getline(std::cin, Response);
if (Response[0] == 'y')
{
return true;
}
if (Response[0] == 'n')
{
return false;
}
return false;
}