Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FBullCowGame.h"
- #include <map>
- #define TMap std::map
- using int32 = int;
- int32 FBullCowGame::GetCurrentTry() const { return MyCurrentTry; }
- int32 FBullCowGame::GetWordLenght() const { return MyHiddenWord.length(); }
- int32 FBullCowGame::GetCurrentRound() const {return TotalRounds;}
- EWordStatus FBullCowGame::IsCorrect(FString Guess)
- {
- if (IsIsogram(Guess))
- {
- return EWordStatus::NOT_ISOGRAM;
- }
- else if (false)
- {
- return EWordStatus::NOT_LOWERCASE;
- }
- else if (Guess.length() != MyHiddenWord.length())
- {
- return EWordStatus::INCORRECT_GUESS_LENGHT;
- }
- else
- {
- return EWordStatus::OK;
- }
- }
- bool FBullCowGame::IsIsogram(FString Guess)
- {
- TMap<char, bool> LettersSeen;
- for (auto Letter : Guess)
- {
- Letter = tolower(Letter);
- if (LettersSeen[Letter])
- {
- return true;
- }
- else
- {
- LettersSeen[Letter] = true;
- }
- }
- int32 FBullCowGame::GetMaxTries() const { return MyHiddenWord.length(); }
- void FBullCowGame::Reset()
- {
- MyCurrentTry = 1;
- TotalRounds++;
- }
- FBullCowCount FBullCowGame::SubmitGuess(FString x)
- {
- FBullCowCount BullCowCount;
- int32 WordLenght = MyHiddenWord.length();
- for (int32 i = 0; i < WordLenght; i++) {
- for (int32 j = 0; j < WordLenght; j++) {
- if (x[i] == MyHiddenWord[j]) {
- if (x[i] == MyHiddenWord[i])
- BullCowCount.Bulls++;
- else
- BullCowCount.Cows++;
- }
- }
- }
- if (BullCowCount.Bulls == MyHiddenWord.length())
- bWin = true;
- MyCurrentTry++;
- return BullCowCount;
- }
- bool FBullCowGame::IsGameWon()const
- {
- return bWin;
- }
- FBullCowGame::FBullCowGame()
- {
- Reset();
- }
Add Comment
Please, Sign In to add comment