Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
118 lines (87 loc) · 2.87 KB
/
Copy pathmain.cpp
File metadata and controls
118 lines (87 loc) · 2.87 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// main.cpp
// BullCowGame
//
// This is the console exe, that makes use of BullCowClass,
// this acts as the view of the MVC pattern, and is responsible
// for all user interaction. for game logic see FBullCowGame class.
//
// Created by Corey Baines on 27/11/16.
// Copyright © 2016 Corey Baines. All rights reserved.
//
#include <iostream>
#include <string>
#include "FBallCowGame.hpp"
using FText = std::string;
using int32 = int;
//Introduce the game functions
void PrintInto();
void PlayGame();
FText GetValidGuess();
bool AskToPlayAgain();
FBullCowGame BCGame;
//Entry point for app
int main() {
bool bPlayAgain = false;
do {
PrintInto();
PlayGame();
bPlayAgain = AskToPlayAgain();
}
while (bPlayAgain);
return 0;
}
void PlayGame() {
BCGame.Reset();
//Loop for number of turns for user guesses
for (int32 count = 1; count <= BCGame.GetMaxTries(); count++) {
FText Guess = GetValidGuess();
//submit valid guess
FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess);
//print number of bulls and cows
std::cout << "Bulls = " << BullCowCount.Bulls;
std::cout << " and Cows = " << BullCowCount.Cows << std::endl;
}
return;
}
//Introduce the game function implimentation
void PrintInto() {
//constexpr int32 WORD_LENGTH = 9;
std::cout << "This is the Bull Cow Game.\n";
std::cout << "Can you guess the " << BCGame.GetHiddenWordLength();
std::cout << " letters isogram I'm thinking of?\n";
return;
}
FText GetValidGuess() {
EGuessStatus Status = EGuessStatus::Invalid_Status;
FText Guess = "";
do {
int32 CurrentTry = BCGame.GetCurrentTry();
// get the guess from the user
std::cout << "Try " << CurrentTry << ". Enter your guess: ";
getline(std::cin,Guess);
Status = BCGame.CheckGuessValidity(Guess);
switch (Status) {
case EGuessStatus::Wrong_Length:
std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n";
break;
case EGuessStatus::Not_Isogram:
std::cout << "Please enter a work without repeating letters.\n";
break;
case EGuessStatus::Not_Lower_Case:
std::cout << "Please enter all lowercase letters.\n";
break;
default:
return Guess;
}
std::cout << std::endl;
} while (Status != EGuessStatus::OK); //Keep looping until there are no errors
return Guess;
}
bool AskToPlayAgain() {
std::cout << "Do you want to play again? (y/n): ";
FText Response = "";
getline(std::cin,Response);
std::cout << std::endl;
return (Response[0] == 'y') || (Response[0] == 'Y');
}