Advertisement
Guest User

FBullCowGame.cpp

a guest
Nov 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include "FBullCowGame.h"
  2.  
  3.  
  4. using int32 = int;
  5.  
  6. FBullCowGame::FBullCowGame()
  7. {
  8. Reset();
  9. }
  10.  
  11. void FBullCowGame::Reset()
  12. {
  13. constexpr int32 MAX_TRIES = 10;
  14.  
  15. MyMaxChances = MAX_TRIES;
  16. const FString HIDDEN_WORD = "plane";
  17. HiddenWord = HIDDEN_WORD;
  18. CurrentChance = 1;
  19. bGameWon = false;
  20. return;
  21. }
  22.  
  23. int32 FBullCowGame::GetMaxChances() const {return MyMaxChances;}
  24. int32 FBullCowGame::GetCurrentChance() const {return CurrentChance;}
  25. int32 FBullCowGame::GetHiddenWordLength() const {return HiddenWord.length();}
  26. bool FBullCowGame::GameWon() const { return bGameWon; }
  27.  
  28. EWordStatus FBullCowGame::GuessCorrect(FString Guess)
  29. {
  30. if(false)
  31. {
  32.  
  33. }
  34. else if (Guess.length() != GetHiddenWordLength())
  35. {
  36.  
  37. return EWordStatus::WrongLength;
  38. }
  39. else
  40. {
  41. return EWordStatus::Valid;
  42. }
  43. }
  44.  
  45. FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
  46. {
  47. CurrentChance++;
  48.  
  49. FBullCowCount BullCowCount;
  50.  
  51. int32 HiddenWordLength = HiddenWord.length();
  52. for (int32 i = 0; i < HiddenWordLength; i++)
  53. {
  54. for (int32 j = 0; j < HiddenWordLength; j++)
  55. {
  56. if (Guess[j] == HiddenWord[i])
  57. {
  58. if (i == j) {
  59. BullCowCount.Bulls++;
  60. }
  61. else{
  62. BullCowCount.Cows++;
  63. }
  64. }
  65. }
  66. }
  67. if (BullCowCount.Bulls == HiddenWordLength) { bGameWon == true; } else { bGameWon == false; }
  68. return BullCowCount;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement