def ev_keydown( self, event: tcod.event.KeyDown ) -> Optional[input_handlers.BaseEventHandler]: if event.sym in (tcod.event.K_q, tcod.event.K_ESCAPE): raise SystemExit() elif event.sym == tcod.event.K_c: try: return input_handlers.MainGameEventHandler(load_game("savegame.sav")) except FileNotFoundError: return input_handlers.PopupMessage(self, "No saved game to load.") except Exception as exc: traceback.print_exc() # Print to stderr. return input_handlers.PopupMessage(self, f"Failed to load save:\n{exc}") pass elif event.sym == tcod.event.K_h: return input_handlers.PopupMessage(self, "Welcome to Phonetics Roguelike!\n\nIn this game, you need to " "find your way out of a human`s oral cavity.\nConsonants will " "try to hinder you, and vowels will help you.\n\nControls:\n[Y][" "K][U] \n[H] [L] - movements " "(arrow keys also work!)\n[B][J][N] " " \n[Q] - open this menu\n[C] - show character info\n[G] - " "grab item\n[D] - drop item\n[I] - open inventory\n[V] - show " "message history\n[Shift] + [.] (i.e. [>]) - move to next " "level\n\nGood luck!\n\n", 18) elif event.sym == tcod.event.K_n: return input_handlers.MainGameEventHandler(new_game.start()) return None
def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[input_handlers.BaseEventHandler]: if event.sym in (tcod.event.K_q, tcod.event.K_ESCAPE): raise SystemExit() elif event.sym == tcod.event.K_c: try: return input_handlers.MainGameEventHandler(load_game("savegame.sav")) except FileNotFoundError: return input_handlers.PopupMessage(self, "No saved game to load.") except Exception as exc: traceback.print_exc() # Print to stderr. return input_handlers.PopupMessage(self, f"Failed to load save:\n{exc}") elif event.sym == tcod.event.K_n: return input_handlers.MainGameEventHandler(new_game()) return None
def ev_keydown( self, event: tcod.event.KeyDown ) -> Optional[input_handlers.BaseEventHandler]: if event.sym in {tcod.event.K_q, tcod.event.K_ESCAPE}: raise SystemExit() elif event.sym == tcod.event.K_c: try: return input_handlers.MainGameEventHandler( load_game(constants.SAVE_FILE)) except FileNotFoundError: return input_handlers.PopupMessage(self, "No saved game to load") except Exception as e: traceback.print_exc() return input_handlers.PopupMessage( self, f"Failed to load save:\n{e}") elif event.sym == tcod.event.K_n: return input_handlers.MainGameEventHandler(new_game()) return None
def ev_keydown( self, event: tcod.event.KeyDown ) -> Optional[input_handlers.BaseEventHandler]: """Handles Main Menu inputs.""" if event.sym in (tcod.event.K_q, tcod.event.K_ESCAPE): # If the player presses "Q" or "ESCAPE", exit the game. raise SystemExit(0) elif event.sym == tcod.event.K_c: # If the player selects "Continue last save" try: return input_handlers.MainGameEventHandler( load_game("savegame.sav")) except FileNotFoundError: return input_handlers.PopupMessage(self, "No saved game to load.") except Exception as exc: # Unexpected error traceback.print_exc() return input_handlers.PopupMessage( self, f"Failed to load save:\n{exc}") elif event.sym == tcod.event.K_n: return input_handlers.MainGameEventHandler(new_game()) return None