My version of code at this point of course

I think it’s a good idea to split lose message to a separate messages and show “You lose!” and call EndGame() in any lose cases, and show additional info about the reason of lose as additional print line.

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

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
	if (bGameOver)
	{
		ClearScreen();
		SetupGame();
	}
	else // check player guess
	{
		if (Input == HiddenWord)
		{
			PrintLine(TEXT("You win!"));
			EndGame();
		}
		else
		{
			if (Input.Len() != HiddenWord.Len()) // Check right number of letters
			{
				PrintLine(TEXT("The hidden word is %i letters long!"), HiddenWord.Len());
			}

			PrintLine(TEXT("\nYou lose!"));
			EndGame();
		}
	}
	// Check is isogram
	// Remove life

	// Check if Lives > 0
	// If yes GuessAgain
	// Show Lives left
	// If no show GameOver and HiddenWord
	// Prompt To Play Again, Press Enter to play again?
	// Check user input
	// PlayAgain or Quit
}

void UBullCowCartridge::SetupGame()
{
	// PrintLine(TEXT("HiddenWord is: %s"), *HiddenWord); // Debug line

	HiddenWord = "isogram";
	Lives = HiddenWord.Len();
	bGameOver = false;

	// Welcoming the player
	PrintLine(TEXT("Welcome to Bull Cows!"));
	PrintLine(TEXT("Guess %i letters isogram!"), HiddenWord.Len());
	PrintLine(TEXT("Type your guess and\npress enter to continue..."));
}

void UBullCowCartridge::EndGame()
{
	bGameOver = true;

	PrintLine(TEXT("Press enter to play again."));
}
1 Like

Amazing code :slight_smile:

Thanks :smiley:

Privacy & Terms