Code as far as Booleans lesson

BullCowCartridge.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Console/Cartridge.h"
#include "BullCowCartridge.generated.h"

UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class BULLCOWGAME_API UBullCowCartridge : public UCartridge
{
	GENERATED_BODY()

	public:
	virtual void BeginPlay() override;
	virtual void OnInput(const FString& Input) override;
	void SetupGame();
	void EndGame();

	// Your declarations go below!
	private:
	FString HiddenWord;
	int32 Lives;
	bool bGameOver;
	
};

BullCowCartridge.cpp

// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"

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

    SetupGame();

    PrintLine(FString::Printf(TEXT("Hidden word is: %s. "), *HiddenWord)); // Debug Line
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    

    // if game is over then ClearScreem() and SetupGame()
    //Check player guess   

    if (bGameOver)
    {
        ClearScreen();
        SetupGame();
    }
    else
    {
        if (Input == HiddenWord)
        {
            PrintLine(TEXT("You win!"));
            EndGame();
        }
        else
        {
            if (Input.Len() != HiddenWord.Len())
            {
                PrintLine(TEXT("The hidden word is %i characters long. \nTry again "), HiddenWord.Len());
            }
            else
            {            
                PrintLine(TEXT("You Lose"));
                EndGame();
            }
        }
    }



    //Check if isogram
    //Check total characters
    //Remove life
    //Print lives left

    //Check lives >0
    //If yes guess again
    //if no game over and HiddenWord
    //prompt to play again
    //check user input
    //play again or quit

}

void UBullCowCartridge::SetupGame()
{
    PrintLine(TEXT("***Bull Cows Game*** "));

    HiddenWord = TEXT("aspired");
    Lives = 4;
    bGameOver = false;

    PrintLine(TEXT("Guess the %i letter isogram: "), HiddenWord.Len()); //Prompt player for guess
    PrintLine(TEXT("Type your guess \nPress enter to continue... ")); 
}

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

Keep up the great work!

Privacy & Terms