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