From b4cd6929ef14d5409b5fab6ed2396b276ff3302b Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Fri, 1 May 2026 19:00:41 -0700 Subject: [PATCH] Improve help menu --- tetris.py | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/tetris.py b/tetris.py index 24ba840..c3db3bb 100644 --- a/tetris.py +++ b/tetris.py @@ -435,14 +435,14 @@ class Game: @staticmethod @lru_cache(maxsize=1) - def make_help_string(am: dict[int, Action]): + def make_action_help_string(am: dict[int, Action]): key_names = [pygame.key.name(k) for k in am.keys()] max_key_len = max(map(len, key_names)) - out = "" + out = "Keys:" for act in am.values(): - if out: - out += "\n" - out += f"{pygame.key.name(act.key).rjust(max_key_len)}: {act.desc}" + out += ( + f"\n{pygame.key.name(act.key).rjust(max_key_len)}: {act.desc}" + ) return out def __init__(self): @@ -450,6 +450,20 @@ class Game: self.high_score = 0 self._score = 0 + @staticmethod + @lru_cache(maxsize=1) + def make_score_help_string(): + return ( + "Points:\n" + "10 lines clear to level up.\n" + f"Soft drop: {Game.DROP_POINTS} * dist. * level\n" + f"Hard drop: {Game.HARD_DROP_POINTS} * dist. * level\n" + f" 1 line: {Game.POINTS_PER_LINE[0]} * level\n" + f" 2 lines: {Game.POINTS_PER_LINE[1]} * level\n" + f" 3 lines: {Game.POINTS_PER_LINE[2]} * level\n" + f" 4 lines: {Game.POINTS_PER_LINE[3]} * level\n" + ) + @property def game_over(self) -> bool: return self._game_over @@ -831,6 +845,7 @@ class Game: "Press \nfor help\nor pause.\n" "\n" f"Level: {self.level:02}\n" + f"Lines: {self.cleared_this_level:02}\n" f"Score: {self.score:05}\n" f" HS: {self.high_score:05}" ) @@ -927,7 +942,11 @@ class Game: def process_and_draw_help_overlay(self): self.draw_gray_overlay() - hs = Game.make_help_string(Game.GAME_ACTION_MAP) + hs = ( + Game.make_action_help_string(Game.GAME_ACTION_MAP) + + "\n\n" + + Game.make_score_help_string() + ) exts = Game.TINY_FONT.compute_extents(hs) sw, sh = self.screen.get_size() @@ -1589,6 +1608,16 @@ GLYPH_DATA = [ "* ", ], ), + Font.Glyph( + "*", + [ + " ", + "* *", + " * ", + "* *", + " ", + ], + ), ]