Basic menu handling
This commit is contained in:
parent
e3a1bf96c2
commit
43001f6ede
|
@ -1,11 +1,12 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
import sys
|
||||||
from .interfaces import Map
|
from .interfaces import Map
|
||||||
from .mapdisplay import MapDisplay
|
from .mapdisplay import MapDisplay
|
||||||
from .settings import Settings
|
from .settings import Settings
|
||||||
from .term_manager import TermManager
|
from .term_manager import TermManager
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
|
from . import menus
|
||||||
|
|
||||||
class GameMode(Enum):
|
class GameMode(Enum):
|
||||||
MAINMENU = auto()
|
MAINMENU = auto()
|
||||||
|
@ -28,6 +29,7 @@ class Game:
|
||||||
def init(self) -> None:
|
def init(self) -> None:
|
||||||
Game.INSTANCE = self
|
Game.INSTANCE = self
|
||||||
self.state = GameMode.MAINMENU
|
self.state = GameMode.MAINMENU
|
||||||
|
self.main_menu = menus.MainMenu()
|
||||||
self.settings = Settings()
|
self.settings = Settings()
|
||||||
self.settings.load_settings()
|
self.settings.load_settings()
|
||||||
self.settings.write_settings()
|
self.settings.write_settings()
|
||||||
|
@ -40,7 +42,7 @@ class Game:
|
||||||
self.player.x = 6
|
self.player.x = 6
|
||||||
self.d = MapDisplay(self.m, self.player)
|
self.d = MapDisplay(self.m, self.player)
|
||||||
|
|
||||||
@classmethod
|
@staticmethod
|
||||||
def load_game(filename):
|
def load_game(filename):
|
||||||
# TODO loading map from a file
|
# TODO loading map from a file
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -64,7 +66,7 @@ class Game:
|
||||||
return KeyValues.UP
|
return KeyValues.UP
|
||||||
|
|
||||||
def handle_key_pressed(self, key: KeyValues) -> None:
|
def handle_key_pressed(self, key: KeyValues) -> None:
|
||||||
|
if self.state == GameMode.PLAY:
|
||||||
if key == KeyValues.UP:
|
if key == KeyValues.UP:
|
||||||
self.player.move_up()
|
self.player.move_up()
|
||||||
if key == KeyValues.DOWN:
|
if key == KeyValues.DOWN:
|
||||||
|
@ -73,6 +75,19 @@ class Game:
|
||||||
self.player.move_left()
|
self.player.move_left()
|
||||||
if key == KeyValues.RIGHT:
|
if key == KeyValues.RIGHT:
|
||||||
self.player.move_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:
|
class Player:
|
||||||
|
|
Loading…
Reference in New Issue