#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
SetupGame();
PrintLine(TEXT("The Hidden Word is: %s."), *HiddenWord);//Debug Line
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
if(bGameOver)
{
ClearScreen();
SetupGame();
}
else//Checking PlayerGuess
{
if(Input == HiddenWord)// is word equal to hidden word
{
PrintLine(TEXT("You Guessed it!"));
EndGame();
}
else
{
if(Input.Len() != HiddenWord.Len())
{
PrintLine(FString::Printf(TEXT("The hidden word is %i letters long. \nyou have lost!"),HiddenWord.Len()));// Magic Number
EndGame();
}
}
}
}
//Guess HiddenWord
//Player guess
//Check if isogram(no repeating letters)
//Check if right amount of characters
//show lifes left
//If not guessed?
//Remove life
//if guessed?
//Keep Life
//No lives?
//Game Over
//Show Hidden Word
//Guess again?
//Has lives?
//won
//Play again?
void UBullCowCartridge::SetupGame()
{
PrintLine(TEXT("Welcome to the Bull-Cows game,\na game where you guess words."));
HiddenWord = TEXT("cake");
Lives = 6;
bGameOver = false;
PrintLine(TEXT("Guess the %i letter word"),HiddenWord.Len());
PrintLine(TEXT("Press 'Tab' and type your guess.\nPress 'Enter' to confirm...."));//prompt player to play againn
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("Would you like to play again?\nIf so, press 'Enter' to continue......."));
}
here is a screenshot of winning the game
here is a screenshot of failing the game.
The cows don’t look too happy
If you are thinking that i didn’t change the hidden word, i changed it from Around to cake
The game looks different because i messed around with post process volume as i know unreal for a year now.
The Course is really helpful, thank you GameDev.tv