Skip to content

Instantly share code, notes, and snippets.

Created August 28, 2017 22:03
Show Gist options
  • Save anonymous/45216c3209ada02a81e435bf57776a62 to your computer and use it in GitHub Desktop.
Save anonymous/45216c3209ada02a81e435bf57776a62 to your computer and use it in GitHub Desktop.
fBullCowGame,cpp
#include "fBullCowGame.h"
fBullCowGame::fBullCowGame() { reset(); }
int32 fBullCowGame::GetMaxTries() const { return MyMaxTries; }
int32 fBullCowGame::CurrentGuess() const { return MyCurrentTries; }
int32 fBullCowGame::GetHiddenWordLength() const { return MyHiddenWord.length(); }
bool fBullCowGame::IsGameWon() const { return bGameWon; }
void fBullCowGame::reset()
{
constexpr int32 MAX_TRIES = 10;
MyMaxTries = MAX_TRIES;
MyCurrentTries = 1;
const FString HIDDEN_WORD = "often";
MyHiddenWord = HIDDEN_WORD;
bGameWon = false;
return;
}
EGuessStatus fBullCowGame::CheckGuessValidity(FString Guess) const
{
//if guess is not an isogram
if (false)
{
return EGuessStatus::Not_An_Isogram;
}
//if guess is wrong word lenth
else if (Guess.length() != GetHiddenWordLength())
{
return EGuessStatus::Wrong_Length;
}
//if guess is not all lower case
else if (false)
{
return EGuessStatus::Not_LowerCase;
}
else
{
return EGuessStatus::ok;
}
}
//increment guess, recieve valid guess, returns counts
fBullCowCount fBullCowGame::SubmitValidGuess(FString Guess)
{
MyCurrentTries++;
//return variable
fBullCowCount BullCowCount;
int32 HiddenWordLength = MyHiddenWord.length();
//loop through letters in hidden word
for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++)
{
//compare hidden word with guess word
for (int32 GChar = 0; GChar < HiddenWordLength; GChar++)
{
//if letters match
if (Guess[GChar] == MyHiddenWord[MHWChar])
{
if (MHWChar == GChar)
{
//if letters match in right spot
BullCowCount.Bulls++;
}
else
{
//if letters match in wrong spot
BullCowCount.Cows++;
}
}
}
}
if (BullCowCount.Bulls == HiddenWordLength)
{
bGameWon = true;
}
else
{
bGameWon = false;
}
return BullCowCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment