import pygame class Game: """Basic Pygame game loop. Subclasses **must** implement: * ``update_game`` – update state, return ``False`` to quit. * ``draw_game`` – render to the screen. """ def __init__(self, title: str, fps: int, size: tuple[int, int]): pygame.init() self.screen = pygame.display.set_mode(size) pygame.display.set_caption(title) self.clock = pygame.time.Clock() self.fps = fps self.size = size def run(self) -> None: running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False running = self.update_game() self.draw_game() pygame.display.flip() self.clock.tick(self.fps) pygame.quit() def update_game(self) -> bool: raise NotImplementedError def draw_game(self) -> None: raise NotImplementedError