My Own Bull&Cow Code

Here is my Code… Right now i have written my own Code … lol

// 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(); //Setting Up Game
}

void UBullCowCartridge::SetupGame()
{
    // Text Macro damit Text auf allen Plattformen richtig angezeigt wird ( Trifft auf ALLE Strings inkl. PrintLine zu )
    PrintLine(TEXT("Willkommen zu Bull & Cows"));

    HiddenWord = TEXT("Cake"); // Set Hidden Word  ->reference in BullCowCartridge.h
    Lives = HiddenWord.Len();        // Set Lives ->reference in BullCowCartridge.h

    PrintLine(FString::Printf(TEXT("You have %i Lives left"), Lives));
    bGameOver = false;

    PrintLine(FString::Printf(TEXT("Gib dein %i Zeichen grosses Wort ein"), HiddenWord.Len()));
    PrintLine(TEXT("Gib dein Wort ein...:"));
}

void UBullCowCartridge::OnInput(const FString &Input) // When the player hits enter
{
    // Make Sure both are the same
    UserInput = Input;
    
    if (Lives < 1)
    {
        bGameOver = true;
        EndGame();
        return;
    }
    LiveAndWordCheck(UserInput);

    //PrintLine(UserInput);
    //PrintLine(Input);
}

void UBullCowCartridge::LiveAndWordCheck(FString UserInput)
{
    if (UserInput == HiddenWord)
    {
        bGameOver = false;
        EndGame();
        return;
    }
     
    if (UserInput.Len() != HiddenWord.Len())
    {
        ClearScreen();
        PrintLine(FString::Printf(TEXT("You have entered the wrong Word\nThe word has %i characters"), HiddenWord.Len()));
        PrintLine(FString::Printf(TEXT("%i Lives left"), --Lives));
        return;
    }
    if (UserInput.Len() == HiddenWord.Len()) 
    {
         ClearScreen();
         PrintLine(FString::Printf(TEXT("You have entered enough Characters\nBut the word is wrong")));
         PrintLine(FString::Printf(TEXT("%i Lives left"), --Lives));
         return;
    }
}

void UBullCowCartridge::EndGame()
{
    switch (bGameOver)
    {
    case false:
        ClearScreen();
        PrintLine(FString::Printf(TEXT("The Hidden word was %s"), *HiddenWord));
        PrintLine(TEXT("You Won\n\n"));
        SetupGame();
        break;
    case true:
        ClearScreen();
        PrintLine(FString::Printf(TEXT("No Lives left")));
        PrintLine(TEXT("You Lost\n\n"));
        SetupGame();
        break;
    }
}

1 Like

Your own code is looking great! Way better than mine :stuck_out_tongue_winking_eye:

Privacy & Terms