BullCowGame...How my code is looking

// 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(TEXT("The HiddenWord is: %s."), *HiddenWord); //Debug Line
}

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

void UBullCowCartridge::SetUpGame()
{
    PrintLine(TEXT("Welcome to Bull Cows!"));

    HiddenWord = TEXT("cakes");
    Lives = HiddenWord.Len();
    bGameOver = false;

    PrintLine(TEXT("Guess the %i letter word! \nYou have %i lives."), HiddenWord.Len(), Lives);
    PrintLine(TEXT("Type in your guess and \npress enter to continue..."));  
}

void UBullCowCartridge::EndGame()
{
    bGameOver = true;
    PrintLine(TEXT("\nPress Enter to play again..."));
}

void UBullCowCartridge::ProcessGuess(FString Guess)
{
    if (HiddenWord == Guess) 
    {
        PrintLine(TEXT("\nYou've Won!"));
        EndGame();
        return;
    }

    if (HiddenWord.Len() == Guess.Len() && Lives > 0) //&& IsIsogram
    {
        PrintLine(TEXT("You have the correct number of charcters \nand it is an isogram. \nYou have lost no lives. \nTry again."));
        return;
    }

    --Lives;

    if (HiddenWord.Len() != Guess.Len() && Lives > 0) 
    {
        PrintLine(TEXT("The hidden word is %i characters long. \nYou have %i out of %i lives left. \nTry again."), HiddenWord.Len(), Lives, HiddenWord.Len());
    }
    else 
    {   
        PrintLine(TEXT("You have 0 lives. You have lost"));
        PrintLine(TEXT("The hidden word was: %s"), *HiddenWord);
        EndGame();
    }
} 


    //Check if it is Isogram
    //Show player Bulls and Cows

1 Like

Very good job! Make sure you post Unreal stuff in the Unreal section.

Privacy & Terms