My Extra Credit Addition for Bulls and Cows: Hints!

Sort of a simple addition, but when processing guesses I decided to add a hint check that checks for the phrase “give me a hint”. Every time you enter this, it will give you another character of the hidden word. So if the word is “play” and if you ask for a hint, it’ll print “p___” to the terminal. The next time you type give me a hint it’ll type “pl__” etc. etc. I didn’t put any penalties for hints, but you could easily decrement a life for a hint.

HintCounter is just an int32 set to 1 that I placed in the header file as a member variable.

    if (Input.Equals("give me a hint")) {
        FString hint = "";
        int32 index = 0;
        if (HintCounter < HiddenWord.Len()) {
            while (index < HintCounter) {
                hint.AppendChar(HiddenWord[index]);
                index += 1;
            }
            for (int i = index; i < HiddenWord.Len(); i++) {
                hint.AppendChar('_');
            }
            PrintLine(FString::Printf(TEXT("Here's a hint for you: %s"), *hint));
            HintCounter++;
            return;
        }
        else {
            PrintLine(TEXT("That's the whole word dude what more do you want from me..."));
        }
    }
1 Like

Intelligent creating a hint check system.

Privacy & Terms