refactored state -> screen
This commit is contained in:
parent
2560a4dcd9
commit
bfabba3d82
7 changed files with 130 additions and 129 deletions
45
game/screens/menu_screens.py
Normal file
45
game/screens/menu_screens.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
"""The main menu state"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import g
|
||||
import game.screens.menus
|
||||
import game.world_tools
|
||||
from game.screens import Reset, ScreenResult
|
||||
from game.screens.game_screens import MainScreen
|
||||
|
||||
class MainMenu(game.screens.menus.ListMenu):
|
||||
"""Main/escape menu."""
|
||||
__slots__ = ()
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the main menu."""
|
||||
items = [
|
||||
game.screens.menus.SelectItem("New game", self.new_game),
|
||||
game.screens.menus.SelectItem("Quit", self.quit),
|
||||
]
|
||||
if hasattr(g, "world"):
|
||||
items.insert(0, game.screens.menus.SelectItem("Continue", self.continue_))
|
||||
|
||||
super().__init__(
|
||||
items=tuple(items),
|
||||
selected=0,
|
||||
x=5,
|
||||
y=5,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def continue_() -> ScreenResult:
|
||||
"""Return to the game."""
|
||||
return Reset(MainScreen())
|
||||
|
||||
@staticmethod
|
||||
def new_game() -> ScreenResult:
|
||||
"""Begin a new game."""
|
||||
g.world = game.world_tools.new_world()
|
||||
return Reset(MainScreen())
|
||||
|
||||
@staticmethod
|
||||
def quit() -> ScreenResult:
|
||||
"""Close the program."""
|
||||
raise SystemExit()
|
||||
Loading…
Add table
Add a link
Reference in a new issue