Skip to content

Commit

Permalink
Refactor Menu::getUserChoice to accept an Input object as a parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Oct 2, 2024
1 parent f2fb23e commit ac86eaa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ std::pair<bool, int> Menu::getPointedItem(
return {false, 0};
}

UserChoice Menu::getUserChoice()
UserChoice Menu::getUserChoice(Input& input)
{
Input input;
int currentItem{0};
while (true)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ class display;
enum class InputAction : char;
enum class Level : char;
enum class UserChoice : char;
class Input;

class Menu final
{
public:
explicit Menu(Display& display);

UserChoice getUserChoice();
UserChoice getUserChoice(Input& input);

void refresh(UserChoice choice);

Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ namespace
UserChoice getUserChoice(Menu& menu)
{
UserChoice choice{UserChoice::MAIN_MENU};
Input input;
while ((choice != UserChoice::EXIT) && (!menu.isLevelPicked(choice)))
{
menu.refresh(choice);
choice = menu.getUserChoice();
choice = menu.getUserChoice(input);
}
return choice;
}
Expand Down

0 comments on commit ac86eaa

Please sign in to comment.