My Bulls and Cows game with random starting words

FBullCowGame.zip (3.6 KB)

In the reset method of our FBullCowGame class i have made an array of strings to store prewords and eachtime the game resets i will give the player a new words to guess, all done by bellow code:

just replace the const Fstring HIDDEN_WORDS = “plane” (inside reset method of our BCGame class) to the codes i wrote bellow.

	const int32 MaxWordNumber = 8;  // length of our RANDOM_WORDS array, we change this if we want mote items in RANDOM_WORDS array (magic number)
	const Fstring Random_Words[MaxWordNumber] = { "crazy", "machine", "music", "plane", "lucky", "right", "lover", "game" }; // words MUST be isogram
	srand(time(NULL)); // set the seed of random to current seconds since January 1, 2000 in the current timezone, otherwise the rand() will allways return same resaults everytime you open the game
	const Fstring HIDDEN_WORD = Random_Words[rand() % MaxWordNumber - 1]; // get a random word from the list
1 Like

I made the same, however I found that this causes the game to restart and set the value for hidden word after the intro, so the word length in the intro was wrong.

So I took it out of the reset methode (MyHiddenWord and HIDDEN_WORD) and created it it’s own method:

FString FBullCowGame::GetHiddenWord()
{
		FString HIDDEN_WORD[] = { "planet", "cat", "brick", "house", "basket", "violent", "mask", "video", "dog", "tea", "dream", "radio", "dinosaur", "crypt", "guts", "trophy", "plane", "plan", "night" };
		srand(time(NULL));
		MyHiddenWord = HIDDEN_WORD[rand() % 19];
		return MyHiddenWord;
}

and then I just added this before the intro:
BCGame.GetHiddenWord();

And all worked well :slight_smile:

2 Likes

Cool… Ill implement that too

Privacy & Terms