Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FBullCowGame.h"
- using int32 = int;
- using FString = std::string;
- FBullCowGame::FBullCowGame()
- {
- Reset();
- }
- void FBullCowGame::Reset() //Decleration of Reset Method
- {
- constexpr int32 MAX_TRIES = 8; //Sets max number of tries
- MyMaxTries = MAX_TRIES;
- const FString HIDDEN_WORD = "planet"; // sets the hidden word
- MyHiddenWord = HIDDEN_WORD;
- MyCurrentTry = 1;
- 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 bGameIsWon;
- }
- EGuessStatus FBullCowGame::CheckGuessValidity(FString Guess) const
- {
- if(false)
- {
- return EGuessStatus::Not_Isogram;
- }
- else if(false)
- {
- return EGuessStatus::Not_Lowercase;
- }
- else if(Guess.length() != GetHiddenWordLength())
- {
- return EGuessStatus::Wrong_Length;
- }
- else
- {
- return EGuessStatus::OK;
- }
- }
- FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess) //Increases the current try by 1
- {
- MyCurrentTry++;
- FBullCowCount BullCowCount;
- int32 WordLength = MyHiddenWord.length();
- for (int32 i = 0 ; i < WordLength ; i++)
- {
- for (int32 j = 0; j < WordLength ; j++)
- {
- if (Guess[i] == MyHiddenWord[j])
- {
- if (i==j)
- {
- BullCowCount.Bulls++;
- }
- else
- {
- BullCowCount.Cows++;
- }
- }
- }
- }
- if (BullCowCount.Bulls == WordLength)
- {
- bGameIsWon = true;
- }
- else
- {
- bGameIsWon = false;
- }
- return BullCowCount;
- }
Add Comment
Please, Sign In to add comment