This commit is contained in:
Yohann D'ANELLO 2020-11-06 18:11:59 +01:00
parent 43001f6ede
commit 8d9b5166b7
3 changed files with 35 additions and 31 deletions

View File

@ -1,13 +1,13 @@
import sys
from typing import Any
import sys
from .interfaces import Map
from .mapdisplay import MapDisplay
from .settings import Settings
from .term_manager import TermManager
from enum import Enum, auto
from . import menus
class GameMode(Enum):
MAINMENU = auto()
PLAY = auto()
@ -34,7 +34,7 @@ class Game:
self.settings.load_settings()
self.settings.write_settings()
def new_game(self):
def new_game(self) -> None:
# TODO generate a new map procedurally
self.m = Map.load("example_map.txt")
self.player = Player()
@ -43,11 +43,11 @@ class Game:
self.d = MapDisplay(self.m, self.player)
@staticmethod
def load_game(filename):
def load_game(filename: str) -> None:
# TODO loading map from a file
raise NotImplementedError()
def run(self, screen):
def run(self, screen: Any) -> None:
while True:
screen.clear()
screen.refresh()
@ -56,13 +56,17 @@ class Game:
self.handle_key_pressed(self.translate_key(key))
def translate_key(self, key: str) -> KeyValues:
if key in (self.settings.KEY_DOWN_SECONDARY, self.settings.KEY_DOWN_PRIMARY):
if key in (self.settings.KEY_DOWN_SECONDARY,
self.settings.KEY_DOWN_PRIMARY):
return KeyValues.DOWN
elif key in (self.settings.KEY_LEFT_PRIMARY, self.settings.KEY_LEFT_SECONDARY):
elif key in (self.settings.KEY_LEFT_PRIMARY,
self.settings.KEY_LEFT_SECONDARY):
return KeyValues.LEFT
elif key in (self.settings.KEY_RIGHT_PRIMARY, self.settings.KEY_RIGHT_SECONDARY):
elif key in (self.settings.KEY_RIGHT_PRIMARY,
self.settings.KEY_RIGHT_SECONDARY):
return KeyValues.RIGHT
elif key in (self.settings.KEY_UP_PRIMARY, self.settings.KEY_UP_SECONDARY):
elif key in (self.settings.KEY_UP_PRIMARY,
self.settings.KEY_UP_SECONDARY):
return KeyValues.UP
def handle_key_pressed(self, key: KeyValues) -> None:

View File

@ -2,32 +2,32 @@ from enum import Enum, auto
class Menu:
values: list
def __init__(self):
self.position = 0
def go_up(self):
def go_up(self) -> None:
self.position = max(0, self.position - 1)
def go_down(self):
def go_down(self) -> None:
self.position = min(len(self.values) - 1, self.position + 1)
def validate(self):
def validate(self) -> None:
return self.values[self.position]
class MainMenuValues(Enum):
START = auto()
SETTINGS = auto()
EXIT = auto()
class MainMenu(Menu):
class MainMenu(Menu):
values = [e for e in MainMenuValues]
class ArbitraryMenu:
class ArbitraryMenu:
def __init__(self, values: list):
super().__init__(self)
self.values = values