Added documentation on a lot of classes and functions (and removed some files I commited by mistake)
This commit is contained in:
committed by
Yohann D'ANELLO
parent
41d1696c9b
commit
8f932604f6
@ -8,24 +8,41 @@ from .settings import Settings
|
||||
|
||||
|
||||
class Menu:
|
||||
"""
|
||||
A Menu object is the logical representation of a menu in the game
|
||||
"""
|
||||
values: list
|
||||
|
||||
def __init__(self):
|
||||
self.position = 0
|
||||
|
||||
def go_up(self) -> None:
|
||||
"""
|
||||
Moves the pointer of the menu on the previous value
|
||||
"""
|
||||
self.position = max(0, self.position - 1)
|
||||
|
||||
def go_down(self) -> None:
|
||||
"""
|
||||
Moves the pointer of the menu on the next value
|
||||
"""
|
||||
self.position = min(len(self.values) - 1, self.position + 1)
|
||||
|
||||
def validate(self) -> Any:
|
||||
"""
|
||||
Selects the value that is pointed by the menu pointer
|
||||
"""
|
||||
return self.values[self.position]
|
||||
|
||||
|
||||
class MainMenuValues(Enum):
|
||||
"""
|
||||
Values of the main menu
|
||||
"""
|
||||
START = 'Nouvelle partie'
|
||||
RESUME = 'Continuer'
|
||||
SAVE = 'Sauvegarder'
|
||||
LOAD = 'Charger'
|
||||
SETTINGS = 'Paramètres'
|
||||
EXIT = 'Quitter'
|
||||
|
||||
@ -34,34 +51,22 @@ class MainMenuValues(Enum):
|
||||
|
||||
|
||||
class MainMenu(Menu):
|
||||
"""
|
||||
A special instance of a menu : the main menu
|
||||
"""
|
||||
values = [e for e in MainMenuValues]
|
||||
|
||||
def handle_key_pressed(self, key: KeyValues, game: Any) -> None:
|
||||
"""
|
||||
In the main menu, we can navigate through options.
|
||||
"""
|
||||
if key == KeyValues.DOWN:
|
||||
self.go_down()
|
||||
if key == KeyValues.UP:
|
||||
self.go_up()
|
||||
if key == KeyValues.ENTER:
|
||||
option = self.validate()
|
||||
if option == MainMenuValues.START:
|
||||
game.new_game()
|
||||
game.state = GameMode.PLAY
|
||||
game.display_actions(DisplayActions.UPDATE)
|
||||
elif option == MainMenuValues.RESUME:
|
||||
game.state = GameMode.PLAY
|
||||
elif option == MainMenuValues.SETTINGS:
|
||||
game.state = GameMode.SETTINGS
|
||||
elif option == MainMenuValues.EXIT:
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
class SettingsMenu(Menu):
|
||||
"""
|
||||
A special instance of a menu : the settings menu
|
||||
"""
|
||||
waiting_for_key: bool = False
|
||||
|
||||
def update_values(self, settings: Settings) -> None:
|
||||
"""
|
||||
The settings can change, so they are updated
|
||||
"""
|
||||
self.values = []
|
||||
for i, key in enumerate(settings.settings_keys):
|
||||
s = settings.get_comment(key)
|
||||
@ -81,7 +86,7 @@ class SettingsMenu(Menu):
|
||||
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str,
|
||||
game: Any) -> None:
|
||||
"""
|
||||
Update settings
|
||||
In the setting menu, we van select a setting and change it
|
||||
"""
|
||||
if not self.waiting_for_key:
|
||||
# Navigate normally through the menu.
|
||||
|
Reference in New Issue
Block a user