11from typing import Optional , Union
22
33import pandas as pd
4+
45from mastermind .main .game_history import GameHistoryManager
56from mastermind .ui .menu .data_menu import DataDisplayMenu
67from mastermind .utils .render_dataframe import render_dataframe
@@ -13,6 +14,7 @@ class ResumeGameMenu(DataDisplayMenu):
1314
1415 name = "Resume Game"
1516 width = 27
17+ _empty_message = "No continuable game found."
1618
1719 def __init__ (self ):
1820 """
@@ -36,12 +38,6 @@ def _render_data(self, data: pd.DataFrame) -> None:
3638 render_dataframe (data )
3739 print ("\n (0) Return to Main Menu" )
3840
39- def _empty_message (self ) -> str :
40- """
41- Returns the message to display when there are no continuable games.
42- """
43- return "No continuable game found."
44-
4541 def _process_option (self , option : str ) -> Union [str , int ]:
4642 """
4743 Processes the selected option, returning either "return" or the index of the selected game.
@@ -56,19 +52,16 @@ def get_option(self) -> Union[str, int]:
5652 if self .menu_length == 0 :
5753 input ("\n Press Enter to continue..." )
5854 return 0
59- else :
60- while True :
61- option = input ("Select a game to resume: " )
62- try :
63- option = int (option )
6455
65- except ValueError :
66- print ("Invalid input. Please enter a number." )
56+ while True :
57+ option = input ("Select a game to resume: " )
58+
59+ if _is_option_valid (option , self .menu_length ):
60+ return int (option )
6761
68- else :
69- if 0 <= option <= self .menu_length :
70- return option
62+ print ("Invalid input or option. Try again." )
63+ self .display ()
7164
72- print ("Invalid option. Try again." )
7365
74- self .display ()
66+ def _is_option_valid (option : int , number_of_options : int ) -> bool :
67+ return option .isdigit () and 0 <= option <= number_of_options
0 commit comments