From 5f8a8c674dffc432ec23fcba591055f0bfd0416b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 18 Jan 2022 14:57:45 -0500 Subject: [PATCH] Complete part 10 --- entity_factories.py | 2 +- input_handlers.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/entity_factories.py b/entity_factories.py index d5fdf1d..8d46696 100644 --- a/entity_factories.py +++ b/entity_factories.py @@ -7,7 +7,7 @@ from entity import Actor, Item player = Actor( char="@", color=(255, 255, 255), - name="PLayer", + name="Player", ai_cls=HostileEnemy, fighter=Fighter(hp=30, defense=2, power=5), inventory=Inventory(capacity=26), diff --git a/input_handlers.py b/input_handlers.py index 50814af..db09e05 100644 --- a/input_handlers.py +++ b/input_handlers.py @@ -1,5 +1,7 @@ from __future__ import annotations +import os + from typing import overload, Callable, Optional, Tuple, TYPE_CHECKING, Union import tcod.event @@ -432,9 +434,18 @@ class MainGameEventHandler(EventHandler): class GameOverEventHandler(EventHandler): + def on_quit(self) -> None: + """Handle exiting out of a finished game.""" + if os.path.exists("savegame.sav"): + os.remove("savegame.sav") # Deletes the active save file. + raise exceptions.QuitWithoutSaving() # Avoid saving a finished game. + + def ev_quit(self, event: tcod.event.Quit) -> None: + self.on_quit() + def ev_keydown(self, event: tcod.event.KeyDown) -> None: if event.sym == tcod.event.K_ESCAPE: - raise SystemExit() + self.on_quit() CURSOR_Y_KEYS = {