Skip to content

Commit 831a37a

Browse files
Add confirm option function
1 parent 3f4dde3 commit 831a37a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

shm/inc/Game.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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

2733
private:
@@ -48,6 +54,7 @@ class Game {
4854
bool isGameWon() const;
4955
bool isGameLost() const;
5056
bool validatingMenuChoose(size_t option);
57+
ConfirmOption confirmOption(std::string announcement);
5158

5259
MenuOption menuOption_ { MenuOption::NoChoose };
5360
};

shm/src/Game.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ bool Game::validatingMenuChoose(size_t option) {
121121
return true;
122122
}
123123

124+
Game::ConfirmOption Game::confirmOption(std::string announcemen) {
125+
std::cout << announcemen << '\n';
126+
char answer;
127+
std::cin >> answer;
128+
if (answer == 'Y' || answer == 'y') {
129+
return ConfirmOption::Yes;
130+
}
131+
if (answer == 'N' || answer == 'n') {
132+
return ConfirmOption::No;
133+
}
134+
std::cout << "Wrong answer, you must choose Y or N\n";
135+
return ConfirmOption::Error;
136+
}
137+
124138
void Game::travel() {
125139

126140
}

0 commit comments

Comments
 (0)