// 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 Hidden Word is: %s"), *HiddenWord); //Debug line
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
// if game over then clearscreen and setup game
// else check player guess
if (bGameOver)
{
ClearScreen();
SetupGame();
}
else
{
if (HiddenWord == Input)
{
PrintLine(TEXT("Congo"));
EndGame();
}
else
{
if (HiddenWord.Len() != Input.Len())
{
PrintLine(TEXT("The no. of charaters are %i in the word"), HiddenWord.Len());
}
PrintLine(TEXT("Lives left %i"), --Lives);
}
if (Lives == 0)
{
PrintLine(TEXT("You Lost"));
PrintLine(TEXT("The Hidden Word is %s"), *HiddenWord);
EndGame();
}
}
//check isogram
//check right characters
//Remove life
//lives > 0 ?
//if yes Guess again show lives left
//if no show game over and hiddenword?
//press enter to play again
//check user input
}
void UBullCowCartridge::SetupGame()
{
//Welcoming the player
PrintLine(TEXT("Welcome to Bull Cows!!"));
HiddenWord = TEXT("Gamers"); //Declaring the word
Lives = HiddenWord.Len(); //set lives
bGameOver = false;
PrintLine(TEXT("Guess the %i letter word"), HiddenWord.Len());
PrintLine(TEXT("The total no. of lives are %i"),Lives);
PrintLine(TEXT("Type your guess Press Enter to continue"));
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("Press Enter to Play Again"));
}
2 Likes
Good code!