From 60ca00b8fa1b013e4b58df7f8b1298b910c411dc Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 6 Nov 2020 16:20:07 +0100 Subject: [PATCH] Generic menu implementation --- dungeonbattle/menus.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 dungeonbattle/menus.py diff --git a/dungeonbattle/menus.py b/dungeonbattle/menus.py new file mode 100644 index 0000000..e188864 --- /dev/null +++ b/dungeonbattle/menus.py @@ -0,0 +1,14 @@ +class Menu: + + def __init__(self, values:list): + self.values = values + self.position = 0 + + def go_up(self): + self.position = max(0, self.position -1) + + def go_down(self): + self.position = min(len(self.values)-1, self.position +1) + + def validate(self): + return self.values[self.position] \ No newline at end of file