My WIP Pseudo code. I ‘coded’ it partially myself but watched the rest of the lecture and made some changes as I went to better align and cover the game’s scope.
One thing I’m struggling with is how to prompt to play again without intentionally failing the game and would appreciate some advice!
// Fill out your copyright notice in the Description page of Project Settings.
#include “BullCowCartridge.h”
void UBullCowCartridge::BeginPlay() // When the game starts
{
// Print Welcome Message
Super::BeginPlay();
PrintLine (TEXT("Well to Bulls and Cows!"));
PrintLine (TEXT("Guess the 4 letter word!")); // Magic Number, Remove
PrintLine (TEXT("Press enter to continue"));
// Setting up Game
HiddenWord = (TEXT("cake")); // Set the HiddenWord
// Set # of Lives
// Prompt PlayerGuess
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
ClearScreen();
// Lives only lost if Answer is Valid (Is Isogram and Correct # of Characters)
// Check if Input is Isogram
// Check if Input contains correct # of characters
// Prompt player to GuessAgain if answer is Invalid
if (Input == HiddenWord)
{
PrintLine(TEXT("You guessed correctly!"));
// Prompt to Play Again?
}
else
{
PrintLine(TEXT("You guessed incorrectly."));
// Remove life
}
// Check if Lives > 0
// If Yes, Display # of Bulls/Cows
// Display Lives Left
// Prompt to GuessAgain
// If No, Print LossScreen and HiddenWord
// Prompt PlayAgain, (Press Enter)
// Check User Input
// PlayAgain or End Game
}