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 {
2222 Exit
2323 };
2424
25+ enum class ConfirmOption {
26+ Yes,
27+ No,
28+ Error
29+ };
30+
2531 void startGame ();
2632
2733private:
@@ -39,6 +45,7 @@ class Game {
3945 void checkCargo (); // NOT IMPLEMENTED
4046 void buy (); // NOT IMPLEMENTED
4147 void sell (); // NOT IMPLEMENTED
48+ bool exitGame ();
4249
4350 std::unique_ptr<Player> player_;
4451 std::unique_ptr<Time> time_;
@@ -48,6 +55,7 @@ class Game {
4855 bool isGameWon () const ;
4956 bool isGameLost () const ;
5057 bool validatingMenuChoose (size_t option);
58+ ConfirmOption confirmOption (std::string announcement);
5159
5260 MenuOption menuOption_ { MenuOption::NoChoose };
5361};
Original file line number Diff line number Diff line change @@ -104,6 +104,9 @@ Game::MenuOption Game::selectOption() {
104104 sell ();
105105 break ;
106106 case MenuOption::Exit :
107+ if (exitGame () == false ) {
108+ menuOption_ = MenuOption::NoChoose;
109+ }
107110 break ;
108111 default :
109112 std::cout << " Option doesn't exists\n " ;
@@ -123,6 +126,32 @@ bool Game::validatingMenuChoose(size_t option) {
123126 return true ;
124127}
125128
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+
126155void Game::travel () {
127156 /* 1. PRINT MAP AND SHOW POSITION
128157 2. PROMPT TO CHOOSE AN ISLAND IN LOOP
You can’t perform that action at this time.
0 commit comments