From 87bac7a32263cbaa1055bf7a1ab41e0506aef3c0 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 25 Jan 2022 15:58:22 -0500 Subject: [PATCH] Add character stats display screen, completing part 11 --- input_handlers.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/input_handlers.py b/input_handlers.py index b23a660..962211a 100644 --- a/input_handlers.py +++ b/input_handlers.py @@ -195,6 +195,55 @@ class AskUserEventHandler(EventHandler): return MainGameEventHandler(self.engine) +class CharacterScreenEventHandler(AskUserEventHandler): + TITLE = "Character Information" + + def on_render(self, console: tcod.Console) -> None: + super().on_render(console) + + if self.engine.player.x <= 30: + x = 40 + else: + x = 0 + + y = 0 + + width = len(self.TITLE) + 4 + + console.draw_frame( + x, + y, + width, + height=7, + title=self.TITLE, + clear=True, + fg=(255, 255, 255), + bg=(0, 0, 0), + ) + + console.print( + x + 1, + y + 1, + f"Level: {self.engine.player.level.current_level}" + ) + console.print( + x + 1, + y + 2, + f"XP: {self.engine.player.level.current_xp}" + ) + console.print( + x + 1, + y + 3, + f"XP for next Level: {self.engine.player.level.experience_to_next_level}" + ) + console.print( + x=x + 1, y=y + 4, string=f"Attack: {self.engine.player.fighter.power}" + ) + console.print( + x=x + 1, y=y + 5, string=f"Defense: {self.engine.player.fighter.defense}" + ) + + class LevelUpEventHandler(AskUserEventHandler): TITLE = "Level Up" @@ -501,6 +550,8 @@ class MainGameEventHandler(EventHandler): return InventoryActivateHandler(self.engine) elif key == tcod.event.K_d: return InventoryDropHandler(self.engine) + elif key == tcod.event.K_c: + return CharacterScreenEventHandler(self.engine) elif key == tcod.event.K_SLASH: return LookHandler(self.engine)