So this took longer than expected

I managed to set up a 3 difficulty game ranging from easy (5 letter word) med (7 letter word) and hard (11 letter word), I know there are easier ways to have done this, but I wanted to try a few things for note taking purposes.

first I added a difficulty input within the PlayGame() method:

std::cout << "Please choose a difficulty: (enter 1-3)\n";
	std::cout << "1 - Easy (5 letter word)\n";
	std::cout << "2 - Medium (7 letter word)\n";
	std::cout << "3 - Hard (11 letter word)\n";
	FString DifficultyInput = "";
	std::getline(std::cin, DifficultyInput);
	int32 Difficulty = atoi(DifficultyInput.c_str()); //string to int
	BCGame.SetDifficulty(Difficulty);

next I added a setter and getter for the difficulty input:

int32 FBullCowGame::GetDifficulty() const { return MyDifficulty; }
//and
void FBullCowGame::SetDifficulty(int32 Difficulty)
{
	MyDifficulty = Difficulty;
}

next I added a method called GetKeyForRand(). I takes the the difficulty input and creates a LIMITED random number used by the the word bank (map):

int32 FBullCowGame::GetKeyForRand()
{
	int32 DifficultyForRand = GetDifficulty();
	if (DifficultyForRand == 1)
	{
		int32 EasyRand = rand() % 5 + 1; //1-5
		return EasyRand;
	}
	else if (DifficultyForRand == 2)
	{
		int32 MedRand = (rand() % (5 + 1)) + 5); //6-10
		return MedRand;
	}
	else
	{
		int32 HardRand = (rand() % (5 + 1)) + 10; // 11-15
		return HardRand;
	}
}

and finally I programmed the map within the Reset() method, with specific map input values corresponding with random values:

void FBullCowGame::Reset()
{
	int32 Key = GetKeyForRand();
	
	TMap <int32, FString> RandomWord{ {1, "plane"}, {2, "brick"},{ 3, "track" },{ 4, "blank" },{ 5, "steal" },
	{ 6, "stumped" },{ 7, "dumbing" },{ 8, "camping" },{ 9, "vintage" },{ 10, "isogram" },
	{ 11, "lumberjacks" },{ 12, "personality" },{ 13, "precautions" },{ 14, "republicans" },{ 15, "speculation" } };
	
	MyHiddenWord = RandomWord[Key];
	MyCurrentTry = 1;
	bGameIsWon = false;
	return;
}

I had to make a few minor changes such as the location of the “can you guess the ____ letter isogram” since it was coming up before the word was even set. But after some tweaking, its running perfectly!

1 Like

Privacy & Terms