File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,12 @@ class Game {
22
22
Exit
23
23
};
24
24
25
+ enum class ConfirmOption {
26
+ Yes,
27
+ No,
28
+ Error
29
+ };
30
+
25
31
void startGame ();
26
32
27
33
private:
@@ -39,6 +45,7 @@ class Game {
39
45
void checkCargo (); // NOT IMPLEMENTED
40
46
void buy (); // NOT IMPLEMENTED
41
47
void sell (); // NOT IMPLEMENTED
48
+ bool exitGame ();
42
49
43
50
std::unique_ptr<Player> player_;
44
51
std::unique_ptr<Time> time_;
@@ -48,6 +55,7 @@ class Game {
48
55
bool isGameWon () const ;
49
56
bool isGameLost () const ;
50
57
bool validatingMenuChoose (size_t option);
58
+ ConfirmOption confirmOption (std::string announcement);
51
59
52
60
MenuOption menuOption_ { MenuOption::NoChoose };
53
61
};
Original file line number Diff line number Diff line change @@ -104,6 +104,9 @@ Game::MenuOption Game::selectOption() {
104
104
sell ();
105
105
break ;
106
106
case MenuOption::Exit :
107
+ if (exitGame () == false ) {
108
+ menuOption_ = MenuOption::NoChoose;
109
+ }
107
110
break ;
108
111
default :
109
112
std::cout << " Option doesn't exists\n " ;
@@ -123,6 +126,32 @@ bool Game::validatingMenuChoose(size_t option) {
123
126
return true ;
124
127
}
125
128
129
+ Game::ConfirmOption Game::confirmOption (std::string announcemen) {
130
+ std::cout << announcemen << ' \n ' ;
131
+ char answer;
132
+ std::cin >> answer;
133
+ if (answer == ' Y' || answer == ' y' ) {
134
+ return ConfirmOption::Yes;
135
+ }
136
+ if (answer == ' N' || answer == ' n' ) {
137
+ return ConfirmOption::No;
138
+ }
139
+ std::cout << " Wrong answer, you must choose Y or N\n " ;
140
+ return ConfirmOption::Error;
141
+ }
142
+
143
+ bool Game::exitGame () {
144
+ while (true ) {
145
+ ConfirmOption exitAnswer = confirmOption (" Are you sure you wanna exit game? Y/N" );
146
+ if (exitAnswer == ConfirmOption::Yes) {
147
+ return true ;
148
+ }
149
+ if (exitAnswer == ConfirmOption::No) {
150
+ return false ;
151
+ }
152
+ }
153
+ }
154
+
126
155
void Game::travel () {
127
156
/* 1. PRINT MAP AND SHOW POSITION
128
157
2. PROMPT TO CHOOSE AN ISLAND IN LOOP
You can’t perform that action at this time.
0 commit comments