Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // # indica una "prepocessor directive" -- #include copies-and-pastes other code. -- Use <> for standard libraries. -- Use "" for files you have created yourself
- #include <iostream>
- #include <string>
- #include "BullCowGame.h"
- using int32 = int;
- using FText = std::string;
- void printIntro();
- int32 main();
- void PlayGame();
- FText getGuess();
- bool AsktoPlayAgain();
- FBullCowGame FbGame; // instantiate a new game.
- int main() {
- bool answer = false;
- do {
- printIntro();
- PlayGame();
- // TODO add a game summary
- answer = AsktoPlayAgain();
- } while (answer);
- return 0;
- }
- void PlayGame()
- {
- FbGame.reset();
- int32 maxTries = FbGame.getMaxTries();
- // TODO change FOR to WHILE loop once we are validating tries
- for (int32 i = 0; i < maxTries; i++) {
- FText guess = getGuess(); //TODO make a loop checking valid
- // TODO submit valid guess to the game
- // TODO print number of bulls and cows
- std::cout << "Your guess was: " << guess << std::endl;
- std::cout << std::endl;
- }
- // TODO summarise game
- }
- void printIntro() {
- constexpr int32 WORD_LENGTH = 9;
- std::cout << "Welcome to Bulls and Cows, a fun word game! Yuuu uuuuu" << std::endl;
- std::cout << "Can you guess the " << WORD_LENGTH;
- std::cout << " letter isogram I'm thinking of?\n";
- std::cout << std::endl;
- return;
- }
- FText getGuess() {
- int32 currentTry = FbGame.getCurrentTry();
- // Get a guess from the player
- std::cout << "Try " << currentTry << ". Enter your guess: ";
- FText guess = "";
- std::getline(std::cin, guess);
- return guess;
- }
- bool AsktoPlayAgain(){
- std::cout << "Vuoi giocare ancora? [y/n]";
- FText answer = "";
- getline(std::cin, answer);
- if (answer[0] == 'y' || answer[0] == 'Y') return true;
- std::cout << std::endl;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement