Yo,
here is my Solution for this Bollean Challenge but i think i overdid a bit XD
It isnt beautiful but i think its ok…
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
// Unreal String Variable (im gegensatz zu normal "string")
// Text Macro damit Text auf allen Plattformen richtig angezeigt wird ( Trifft auf ALLE Strings (FStrings) zu )
// FString HiddenWord; // wird in der Headerfile Deklariert ( BullCowCartridge.h)
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
SetupGame(); //Setting Up Game
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
UserInput = Input;
if (Input.Len() == HiddenWord.Len())
{
if (Input == HiddenWord)
{
EndGame();
}
}
else if (Input.Len() != HiddenWord.Len())
{
LiveAndWordCheck();
}
PrintLine(Input);
}
/*
inside of "isInput Correct"
Method: (void?) LostLife(): (Life--) -> Substract & Check Life
If (life != 0)
Method: (void?) LostLife(): printLine(Text(You have lost a life try again)) -> Substract & Check Life
Method: (int?) CheckBuC(): -> Check B&C return value as INT? Value(2,3)
If( Hidden word has B&C inside)
Show B&C
else
NO B&C
else
Method: (void?) LostLife(): printLine(Text(Life is 0. You Lost)) -> Substract & Check Life
*/
// Wanna play again? If yes -> Play again
// Wanna quit? If yes -> Boom
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("HiddenWord"); // Set Hidden Word ->reference in BullCowCartridge.h
Lives = 3; // Set Lives ->reference in BullCowCartridge.h
bGameOver = false;
PrintLine(FString::Printf(TEXT("Gib dein %i Zeichen grosses Wort ein"), HiddenWord.Len())); //todo Magic Number remove
PrintLine(TEXT("Druecke Tab um fortzufahren."));
}
void UBullCowCartridge::LiveAndWordCheck()
{
if(Lives <= 1)
{
bGameOver = true;
EndGame();
}
else if (UserInput.Len() <= HiddenWord.Len())
{
PrintLine(FString::Printf(TEXT("You have not given enough characters! \nThe word has %i characters"), HiddenWord.Len() ));
Lives --;
PrintLine(FString::Printf(TEXT("%i Lives left"), Lives ));
}
else if (UserInput.Len() >= HiddenWord.Len())
{
PrintLine(FString::Printf(TEXT("You have entered too many characters! \nThe word has %i characters") , HiddenWord.Len() ));
Lives --;
PrintLine(FString::Printf(TEXT("%i Lives left"), Lives ));
}
}
void UBullCowCartridge::EndGame()
{
// if game is over then do something ( ClearScreen() and SteupGame() the game ) --Check
// else
//Checking PlayerGuess
switch (bGameOver)
{
case false:
ClearScreen();
PrintLine(FString::Printf(TEXT("The Hidden word was %s"), *HiddenWord ));
PrintLine(TEXT("You Won"));
bGameOver = true;
break;
case true:
ClearScreen();
PrintLine(FString::Printf(TEXT("%i No Lives left"), Lives ));
PrintLine(TEXT("You Lost"));
SetupGame();
break;
}
/* if ( bGameOver != true )
{
ClearScreen();
PrintLine(FString::Printf(TEXT("The Hidden word was %s"), *HiddenWord ));
PrintLine(TEXT("You Won"));
bGameOver = true;
} else if (bGameOver)
{
ClearScreen();
PrintLine(FString::Printf(TEXT("%i No Lives left"), Lives ));
PrintLine(TEXT("You Lost"));
SetupGame();
}
else
{
HiddenWord = TEXT("Something went wrong... Try again");
} */
}