Advertisement
Guest User

Main.cpp

a guest
Oct 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. // # indica una "prepocessor directive" -- #include copies-and-pastes other code. -- Use <> for standard libraries. -- Use "" for files you have created yourself
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include "BullCowGame.h"
  6.  
  7. using int32 = int;
  8. using FText = std::string;
  9.  
  10. void printIntro();
  11. int32 main();
  12. void PlayGame();
  13. FText getGuess();
  14. bool AsktoPlayAgain();
  15.  
  16. FBullCowGame FbGame; // instantiate a new game.
  17.  
  18.  
  19. int main() {
  20.     bool answer = false;
  21.  
  22.     do {
  23.         printIntro();
  24.         PlayGame();
  25.         // TODO add a game summary
  26.         answer = AsktoPlayAgain();
  27.  
  28.     } while (answer);
  29.  
  30.     return 0;
  31. }
  32.  
  33. void PlayGame()
  34. {
  35.     FbGame.reset();
  36.     int32 maxTries = FbGame.getMaxTries();
  37.     // TODO change FOR to WHILE loop once we are validating tries  
  38.     for (int32 i = 0; i < maxTries; i++) {
  39.         FText guess = getGuess();  //TODO make a loop checking valid
  40.  
  41.         // TODO submit valid guess to the game
  42.         // TODO print number of bulls and cows
  43.         std::cout << "Your guess was: " << guess << std::endl;
  44.         std::cout << std::endl;
  45.     }
  46.  
  47.     // TODO summarise game
  48. }
  49.  
  50.  
  51. void printIntro() {
  52.     constexpr int32 WORD_LENGTH = 9;
  53.     std::cout << "Welcome to Bulls and Cows, a fun word game! Yuuu uuuuu" << std::endl;
  54.     std::cout << "Can you guess the " << WORD_LENGTH;
  55.     std::cout << " letter isogram I'm thinking of?\n";
  56.     std::cout << std::endl;
  57.  
  58.     return;
  59. }
  60.  
  61. FText getGuess() {
  62.     int32 currentTry = FbGame.getCurrentTry();
  63.  
  64.     // Get a guess from the player
  65.     std::cout << "Try " << currentTry << ". Enter your guess: ";
  66.     FText guess = "";
  67.     std::getline(std::cin, guess);
  68.    
  69.     return guess;
  70. }
  71.  
  72. bool AsktoPlayAgain(){
  73.     std::cout << "Vuoi giocare ancora? [y/n]";
  74.     FText answer = "";
  75.     getline(std::cin, answer);
  76.  
  77.     if (answer[0] == 'y' || answer[0] == 'Y') return true;
  78.  
  79.     std::cout << std::endl;
  80.     return false;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement