Guest User

Untitled

a guest
Feb 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include "FBullCowGame.h"
  2.  
  3. using int32 = int;
  4. using FString = std::string;
  5.  
  6. FBullCowGame::FBullCowGame()
  7. {
  8. Reset();
  9. }
  10.  
  11. void FBullCowGame::Reset() //Decleration of Reset Method
  12. {
  13.  
  14. constexpr int32 MAX_TRIES = 8; //Sets max number of tries
  15. MyMaxTries = MAX_TRIES;
  16.  
  17. const FString HIDDEN_WORD = "planet"; // sets the hidden word
  18. MyHiddenWord = HIDDEN_WORD;
  19.  
  20. MyCurrentTry = 1;
  21.  
  22. return;
  23. }
  24.  
  25.  
  26.  
  27. int32 FBullCowGame::GetMaxTries() const
  28. {
  29. return MyMaxTries;
  30. }
  31.  
  32. int32 FBullCowGame::GetCurrentTry() const
  33. {
  34. return MyCurrentTry;
  35. }
  36.  
  37. int32 FBullCowGame::GetHiddenWordLength() const
  38. {
  39.  
  40. return MyHiddenWord.length();
  41. }
  42.  
  43. bool FBullCowGame::IsGameWon() const
  44. {
  45. return bGameIsWon;
  46. }
  47.  
  48. EGuessStatus FBullCowGame::CheckGuessValidity(FString Guess) const
  49. {
  50. if(false)
  51. {
  52. return EGuessStatus::Not_Isogram;
  53.  
  54. }
  55. else if(false)
  56. {
  57. return EGuessStatus::Not_Lowercase;
  58. }
  59. else if(Guess.length() != GetHiddenWordLength())
  60. {
  61. return EGuessStatus::Wrong_Length;
  62. }
  63. else
  64. {
  65. return EGuessStatus::OK;
  66. }
  67. }
  68.  
  69. FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess) //Increases the current try by 1
  70. {
  71. MyCurrentTry++;
  72. FBullCowCount BullCowCount;
  73.  
  74. int32 WordLength = MyHiddenWord.length();
  75. for (int32 i = 0 ; i < WordLength ; i++)
  76. {
  77. for (int32 j = 0; j < WordLength ; j++)
  78. {
  79. if (Guess[i] == MyHiddenWord[j])
  80. {
  81. if (i==j)
  82. {
  83. BullCowCount.Bulls++;
  84. }
  85. else
  86. {
  87. BullCowCount.Cows++;
  88. }
  89. }
  90. }
  91.  
  92.  
  93. }
  94.  
  95. if (BullCowCount.Bulls == WordLength)
  96. {
  97. bGameIsWon = true;
  98. }
  99. else
  100. {
  101. bGameIsWon = false;
  102. }
  103.  
  104.  
  105.  
  106. return BullCowCount;
  107. }
Add Comment
Please, Sign In to add comment