Basic menu handling

This commit is contained in:
Nicolas Margulies 2020-11-06 18:06:28 +01:00
parent e3a1bf96c2
commit 43001f6ede
1 changed files with 26 additions and 11 deletions

View File

@ -1,11 +1,12 @@
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()
@ -28,6 +29,7 @@ class Game:
def init(self) -> None:
Game.INSTANCE = self
self.state = GameMode.MAINMENU
self.main_menu = menus.MainMenu()
self.settings = Settings()
self.settings.load_settings()
self.settings.write_settings()
@ -40,7 +42,7 @@ class Game:
self.player.x = 6
self.d = MapDisplay(self.m, self.player)
@classmethod
@staticmethod
def load_game(filename):
# TODO loading map from a file
raise NotImplementedError()
@ -64,15 +66,28 @@ class Game:
return KeyValues.UP
def handle_key_pressed(self, key: KeyValues) -> None:
if key == KeyValues.UP:
self.player.move_up()
if key == KeyValues.DOWN:
self.player.move_down()
if key == KeyValues.LEFT:
self.player.move_left()
if key == KeyValues.RIGHT:
self.player.move_right()
if self.state == GameMode.PLAY:
if key == KeyValues.UP:
self.player.move_up()
if key == KeyValues.DOWN:
self.player.move_down()
if key == KeyValues.LEFT:
self.player.move_left()
if key == KeyValues.RIGHT:
self.player.move_right()
if self.state == GameMode.MAINMENU:
if key == KeyValues.DOWN:
self.main_menu.go_down()
if key == KeyValues.UP:
self.main_menu.go_up()
if key == KeyValues.ENTER:
option = self.main_menu.validate()
if option == menus.MainMenuValues.START:
self.state = GameMode.PLAY
elif option == menus.MainMenuValues.SETTINGS:
self.state = GameMode.SETTINGS
elif option == menus.MainMenuValues.EXIT:
sys.exit(0)
class Player: