-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
66 lines (60 loc) · 2.13 KB
/
test.cpp
File metadata and controls
66 lines (60 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
#include "FBullCowGame.h"
using int32 = int;
using string = std::string;
void PrintIntro(); //Print brief introduction
void PlayGame();
std::string GetGuess(); // Asks for input and returns what the user has input
void PrintBack(std::string guess); // Gets a string input and returns it (should be getGues())
bool AskToPlayAgain(); // Asks to play again, returns true if yes
FBullCowGame BCGame; //Instantiate
int main(){
do {
BCGame.ResetGame();
PrintIntro();
PlayGame();
}
while (AskToPlayAgain() == true);
return 0;
}
void PlayGame(){
int32 maxTries = BCGame.GetMaxTries();
// TODO change for to while when validating
for (int32 i = 0; i< maxTries; ++i){
i = BCGame.GetCurrentTry();
string guess = GetGuess(); // TODO Check it
BullCowCount BullCowCount = BCGame.SubmitGuess(guess);
std::cout << std::endl << "Bulls = " << BullCowCount.Bulls <<". Cows = " << BullCowCount.Cows << std::endl;
// Return the valid GetGuess
// Print number of bulls and cows
BCGame.SetCurrentTry(BCGame.GetCurrentTry()); //I dont get wht the current try increments but ok
}
}
//Introduce the game
void PrintIntro(){
int32 WORLD_LENGHT = BCGame.getHiddenWordLength(BCGame.getHiddenWord());
std::cout << std::endl << "----------------------" << std::endl <<"Welcome to Bull and Cows, a fun word game. " << std::endl;
std::cout << "Can you guess the " << WORLD_LENGHT << " letter isogram I'm thinking of?" << std::endl;
return;
}
//Ask for guess
std::string GetGuess(){
std::string guess = "";
std::cout << std::endl << "Current try: " << BCGame.GetCurrentTry()<< ". What's your guess?" << std::endl;
getline(std::cin, guess);
return guess;
}
//Prints the guess back on screen
void PrintBack(std::string guess){
std::cout << "Your guess was " << guess << "." << std::endl;
}
//Returns true if the user input starts with 'y' or 'Y' if user wants to play again
bool AskToPlayAgain(){
bool res = false;
std::cout <<"Do you want to play again? ";
std::string response = "";
getline(std::cin, response);
if (response[0] == 'y' || response [0] == 'Y') res = true;
return res;
}