Sharing a sample of what my code is like so far - Booleans Lecture

Here’s how my code is looking like so far in the course.

#include "BullCowCartridge.h"

void UBullCowCartridge::BeginPlay(){ // When the game starts

    Super::BeginPlay();

    SetUpGame();    

    PrintLine(TEXT("The HiddenWord is: %s"), *HiddenWord);   //Debug Line    
}

void UBullCowCartridge::OnInput(const FString& Input){ // When the player hits enter
       
    if (bGameOver) {
        ClearScreen(); 
        SetUpGame();
    }
    else {
        
    HiddenWord.Len();
    
    //Checking the PlayerGuess

    if (Input == HiddenWord) { 
        PrintLine(TEXT("Your guess was: ")+Input);
        PrintLine(TEXT("Correct! You got the hidden word and won!"));
        EndGame();
    }
    else {
        PrintLine(TEXT("Your guess was: ")+Input);      
          
        if (Input.Len() != HiddenWord.Len()) {
            PrintLine(TEXT("The Hidden Word is %i characters long - try again!"), HiddenWord.Len()); 
        }
        PrintLine(TEXT("Incorrect! Game Over!"));
        EndGame();
      }
    }

    //If the game is over, ClearScreen() and SetUpGame() - Resetting the game
    //Else, keep checking the PlayerGuess
}

void UBullCowCartridge::SetUpGame() {


    //Welcoming the Player
    PrintLine(TEXT("Hi there! Welcome to Bulls and Cows!"));  
    HiddenWord = TEXT("cakes"); 
    Lives = 5;               
    PrintLine(TEXT("Guess the %i letter word!"), HiddenWord.Len()); 
    PrintLine(TEXT("To begin, please press Tab to start, \ntype in your guess and hit Enter!")); 
    bGameOver = false;
}

void UBullCowCartridge::EndGame() {
    bGameOver = true;
    PrintLine(TEXT("Press enter to play again."));
}

Looking very good. How do you feel about your code?

I’m feeling pretty satisfied with how it’s going so far. If there’s one point I’m having troubles with at the moment, its the lesson for Arguments and parameters, since I’m trying to make sure the content in the OnInput function is copy-pasted correctly in a way that doesn’t cause bugs to show up. But so far so good at the moment, and still enjoying the learning process

Privacy & Terms