Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FBullCowGame.h"
- using int32 = int;
- FBullCowGame::FBullCowGame()
- {
- Reset();
- }
- void FBullCowGame::Reset()
- {
- constexpr int32 MAX_TRIES = 10;
- MyMaxChances = MAX_TRIES;
- const FString HIDDEN_WORD = "plane";
- HiddenWord = HIDDEN_WORD;
- CurrentChance = 1;
- bGameWon = false;
- return;
- }
- int32 FBullCowGame::GetMaxChances() const {return MyMaxChances;}
- int32 FBullCowGame::GetCurrentChance() const {return CurrentChance;}
- int32 FBullCowGame::GetHiddenWordLength() const {return HiddenWord.length();}
- bool FBullCowGame::GameWon() const { return bGameWon; }
- EWordStatus FBullCowGame::GuessCorrect(FString Guess)
- {
- if(false)
- {
- }
- else if (Guess.length() != GetHiddenWordLength())
- {
- return EWordStatus::WrongLength;
- }
- else
- {
- return EWordStatus::Valid;
- }
- }
- FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
- {
- CurrentChance++;
- FBullCowCount BullCowCount;
- int32 HiddenWordLength = HiddenWord.length();
- for (int32 i = 0; i < HiddenWordLength; i++)
- {
- for (int32 j = 0; j < HiddenWordLength; j++)
- {
- if (Guess[j] == HiddenWord[i])
- {
- if (i == j) {
- BullCowCount.Bulls++;
- }
- else{
- BullCowCount.Cows++;
- }
- }
- }
- }
- if (BullCowCount.Bulls == HiddenWordLength) { bGameWon == true; } else { bGameWon == false; }
- return BullCowCount;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement