Advertisement
Guest User

main.cpp

a guest
Nov 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include "FBullCowGame.h"
  4. #include <algorithm>
  5.  
  6. using FText = std::string;
  7. using int32 = int;
  8.  
  9. void Intro();
  10.  
  11. void Play();
  12.  
  13. FText Ask();
  14.  
  15. bool Retry();
  16.  
  17. FBullCowGame BCGame;
  18.  
  19. int32 main()
  20. {
  21. bool RetryB = false;
  22. do {
  23. Intro();
  24. Play();
  25. RetryB = Retry();
  26. } while (RetryB == true);
  27. }
  28.  
  29. void Play()
  30. {
  31. BCGame.Reset();
  32. int32 MaxChances = BCGame.GetMaxChances();
  33.  
  34.  
  35.  
  36. while (!BCGame.GameWon() && BCGame.GetCurrentChance() <= MaxChances) { //for (int32 Chance = 1; Chance <= MaxChances; Chance++)
  37. {
  38. FText Guess = Ask();
  39.  
  40. FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess);
  41.  
  42. std::cout << "Bulls = " << BullCowCount.Bulls;
  43. std::cout << ". Cows = " << BullCowCount.Cows << "." << std::endl;
  44.  
  45. // submit valid guess
  46. std::cout << std::endl;
  47. std::cout << "You wrote: " << Guess << "!\n";
  48. std::cout << std::endl;
  49. }
  50. }
  51. }
  52.  
  53. FText Ask()
  54. {
  55. EWordStatus Status = EWordStatus::Invalid;
  56. do {
  57.  
  58. int32 CurrentChance = BCGame.GetCurrentChance();
  59. // Get input
  60. std::cout << "Try " << CurrentChance << ".\n";
  61. FText Guess = "";
  62. std::cout << "Input your guess: ";
  63. std::getline(std::cin, Guess);
  64. std::transform(Guess.begin(), Guess.end(), Guess.begin(), ::tolower);
  65. Status = BCGame.GuessCorrect(Guess);
  66.  
  67. switch (Status)
  68. {
  69. case EWordStatus::WrongLength:
  70. std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n\n";
  71. break;
  72. case EWordStatus::NotIsogram:
  73. std::cout << "Word must be an Isogram (word without repeating letters!)\n\n";
  74. break;
  75. default:
  76. return Guess;
  77. }
  78. } while (Status != EWordStatus::Valid);
  79. }
  80.  
  81.  
  82. bool Retry()
  83. {
  84. std::cout << "Would you like to play again? (Y/N) ";
  85. FText Response = "";
  86. std::getline(std::cin, Response);
  87. std::cout << std::endl;
  88.  
  89.  
  90. return (Response[0] == 'y') || (Response[0] == 'Y');
  91. }
  92.  
  93.  
  94. void Intro()
  95. {
  96. // Introduction
  97.  
  98. std::cout << "Welcome to Bulls and Cows! A puzzling word game!\n";
  99. std::cout << "Can you guess the " << BCGame.GetHiddenWordLength() << " letter Isogram?\n";
  100. std::cout << std::endl;
  101. return;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement