Skip to content

Instantly share code, notes, and snippets.

@92408512049
Created June 1, 2017 22:39
Show Gist options
  • Save 92408512049/4438c0ed2b77079cfa379923d89d31a1 to your computer and use it in GitHub Desktop.
Save 92408512049/4438c0ed2b77079cfa379923d89d31a1 to your computer and use it in GitHub Desktop.
Class_Body
#include "FBullCowGame.h"
using int32 = int;
FBullCowGame::FBullCowGame()
{
Reset();
}
void FBullCowGame::Reset() // All game session values that can be modified.
{
constexpr int32 MAX_TRIES = 5;
MyMaxTries = MAX_TRIES;
constexpr int32 CURRENT_TRY = 1;
MyCurrentTry = CURRENT_TRY;
const FString HIDDEN_WORD = "planet";
MyHiddenWord = HIDDEN_WORD;
return;
}
int32 FBullCowGame::GetMaxTries() const
{
return MyMaxTries;
}
int32 FBullCowGame::GetCurrentTry() const
{
return MyCurrentTry;
}
int32 FBullCowGame::GetHiddenWordLength() const
{
return MyHiddenWord.length();
}
bool FBullCowGame::IsGameWon() const
{
return false;
}
EGuessStatus FBullCowGame::CheckGuessValidity(FString Guess) const
{
if (false) // If guess isn't an isogram.
{
return EGuessStatus::Not_Isogram;
}
else if (false) // If the guess isn't all lower case.
{
return EGuessStatus::Not_Lowercase;
}
else if (Guess.length() != GetHiddenWordLength()) // If the guess length is wrong.
{
return EGuessStatus::Wrong_Length;
}
else // otherwise, return OK.
{
return EGuessStatus::OK;
}
}
// Receives a valid guess, increments turn, and returns count.
FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess)
{
MyCurrentTry++;
FBullCowCount BullCowCount;
// Loop through all letters in the hidden word.
for (int32 MHWChar = 0; MHWChar < GetHiddenWordLength(); MHWChar++)
{
// Compare letters against the player's guess.
for (int32 GChar = 0; GChar < GetHiddenWordLength(); GChar++)
{
// If they match, then...
if (Guess[GChar] == MyHiddenWord[MHWChar])
{
if (MHWChar == GChar)
{
// ...incriment Bulls.
BullCowCount.Bulls++;
}
// ...otherwise...
else
{
// ...increment Cows.
BullCowCount.Cows++;
}
}
}
}
return BullCowCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment