Bind Return key to menus

This commit is contained in:
Yohann D'ANELLO 2020-11-06 18:25:02 +01:00
parent 8d9b5166b7
commit 60d6c7509a
3 changed files with 6 additions and 1 deletions

View File

@ -68,6 +68,8 @@ class Game:
elif key in (self.settings.KEY_UP_PRIMARY, elif key in (self.settings.KEY_UP_PRIMARY,
self.settings.KEY_UP_SECONDARY): self.settings.KEY_UP_SECONDARY):
return KeyValues.UP return KeyValues.UP
elif key == self.settings.KEY_ENTER:
return KeyValues.ENTER
def handle_key_pressed(self, key: KeyValues) -> None: def handle_key_pressed(self, key: KeyValues) -> None:
if self.state == GameMode.PLAY: if self.state == GameMode.PLAY:

View File

@ -1,4 +1,5 @@
from enum import Enum, auto from enum import Enum, auto
from typing import Any
class Menu: class Menu:
@ -13,7 +14,7 @@ class Menu:
def go_down(self) -> None: def go_down(self) -> None:
self.position = min(len(self.values) - 1, self.position + 1) self.position = min(len(self.values) - 1, self.position + 1)
def validate(self) -> None: def validate(self) -> Any:
return self.values[self.position] return self.values[self.position]

View File

@ -27,6 +27,8 @@ class Settings:
['d', 'Touche principale pour aller vers la droite'] ['d', 'Touche principale pour aller vers la droite']
self.KEY_RIGHT_SECONDARY = \ self.KEY_RIGHT_SECONDARY = \
['KEY_RIGHT', 'Touche secondaire pour aller vers la droite'] ['KEY_RIGHT', 'Touche secondaire pour aller vers la droite']
self.KEY_ENTER = \
['\n', 'Touche pour valider un menu']
self.TEXTURE_PACK = ['ASCII', 'Pack de textures utilisé'] self.TEXTURE_PACK = ['ASCII', 'Pack de textures utilisé']
def __getattribute__(self, item: str) -> Any: def __getattribute__(self, item: str) -> Any: