Skip to content

Commit 61656ce

Browse files
Add exit game function
1 parent 831a37a commit 61656ce

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

shm/inc/Game.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Game {
4545
void checkCargo(); //NOT IMPLEMENTED
4646
void buy(); //NOT IMPLEMENTED
4747
void sell(); //NOT IMPLEMENTED
48+
bool exitGame();
4849

4950
std::unique_ptr<Player> player_;
5051
std::unique_ptr<Time> time_;

shm/src/Game.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ Game::MenuOption Game::selectOption() {
102102
sell();
103103
break;
104104
case MenuOption::Exit :
105+
if (exitGame() == false) {
106+
menuOption_ = MenuOption::NoChoose;
107+
}
105108
break;
106109
default:
107110
std::cout << "Option doesn't exists\n";
@@ -135,6 +138,18 @@ Game::ConfirmOption Game::confirmOption(std::string announcemen) {
135138
return ConfirmOption::Error;
136139
}
137140

141+
bool Game::exitGame() {
142+
while (true) {
143+
ConfirmOption exitAnswer = confirmOption("Are you sure you wanna exit game? Y/N";
144+
if (exitAnswer == ConfirmOption::Yes) {
145+
return true;
146+
}
147+
if (exitAnswer == ConfirmOption::No) {
148+
return false
149+
}
150+
}
151+
}
152+
138153
void Game::travel() {
139154

140155
}

0 commit comments

Comments
 (0)