Hi!
Here are my functions so far!
CPP File:
#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
PrintLine(TEXT("Welcome to Bull Cows!"));
PrintLine(TEXT("Press Enter to continue..."));
InitGame(); // Play the Bull & Cows's Videogame!
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
ClearScreen();
if (Input.Compare(HiddenWord) == 0)
{
PrintLine(TEXT("Correct! You Win!"));
}
else
{
PrintLine(TEXT("Wrong anwser. Try again"));
}
// ----------------------------------------
// ----------- PSEUDOCODE -----------
// ----------------------------------------
//
// PrintWelcomeMessage()
//
// StartTheGame()
// {
// SetLifes(amount)
// SetHiddenWord(value)
//
// AsksForGuess()
//
// CHECK:
// If: Is not a Isogram && Chars's length match input's guess length.
//
// WinTheGame()
//
// Else:
//
// SubstractLife()
//
// CHECK:
// If: Are lifes > 0?
//
// AsksForGuess()
//
// Else:
//
// PrintGameLost()
// PromptTryAgain()
//
// CHECK:
// If: Play Again?
//
// AsksForGuess()
//
// Else:
//
// ExitTheGame()
//
// }
}
void UBullCowCartridge::InitGame()
{
SetHiddenWord("Cake");
SetLives(4);
}
void UBullCowCartridge::SetLives(int32 _lives)
{
Lives = _lives;
}
void UBullCowCartridge::SubstractLive()
{
--Lives;
}
void UBullCowCartridge::SetHiddenWord(FString word)
{
HiddenWord = word;
}
int32 UBullCowCartridge::GetLives()
{
return Lives;
}
Header File:
#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;
// Executes the game.
void InitGame();
// Gets the current Lives amount
int32 GetLives();
// Sets the lives amount.
void SetLives(int32 amount);
// Substract 1 live.
void SubstractLive();
// Sets the hidden word.
void SetHiddenWord(FString word);
// Your declarations go below!
private:
FString HiddenWord;
int32 Lives;
};