From 30c4773f1316e897d38a8a0a2b1ef3202c7ca3b7 Mon Sep 17 00:00:00 2001 From: paulusja Date: Thu, 16 Apr 2026 16:16:50 +0200 Subject: [PATCH] Add type annotations. --- snake/input_manager.py | 2 +- snake/main.py | 3 ++- snake/snake.py | 4 ++-- snake/window.py | 7 ++++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/snake/input_manager.py b/snake/input_manager.py index 5fb2344..301cefa 100644 --- a/snake/input_manager.py +++ b/snake/input_manager.py @@ -4,7 +4,7 @@ import pygame class InputManager: QUIT = 0 - def process_input(self): + def process_input(self) -> int: last_input = None for event in pygame.event.get(): diff --git a/snake/main.py b/snake/main.py index 11025ab..08eee5a 100644 --- a/snake/main.py +++ b/snake/main.py @@ -2,8 +2,9 @@ import pygame from window import Window from input_manager import InputManager from snake import Snake +from game_object import GameObject -def draw(window, game_objs): +def draw(window: Window, game_objs: list[GameObject]) -> None: window.reset() for obj in game_objs: diff --git a/snake/snake.py b/snake/snake.py index 72181a9..7900eae 100644 --- a/snake/snake.py +++ b/snake/snake.py @@ -3,12 +3,12 @@ from game_object import GameObject class Snake(GameObject): - def __init__(self, start_position, radius, color): + def __init__(self, start_position: tuple|list, radius: float|int, color: tuple) -> None: self.__pos = start_position self.__radius = radius self.__color = color - def draw(self, surface): + def draw(self, surface: pygame.Surface) -> None: pygame.draw.circle(surface=surface, color=self.__color, center=self.__pos, diff --git a/snake/window.py b/snake/window.py index fe345ed..3852705 100644 --- a/snake/window.py +++ b/snake/window.py @@ -1,18 +1,19 @@ import pygame +from game_object import GameObject class Window: - def __init__(self, title, size, background_color=(0, 0, 0)): + def __init__(self, title: str, size: tuple, background_color: tuple=(0, 0, 0)) -> None: pygame.init() pygame.display.set_caption(title) self.__surface = pygame.display.set_mode(size=size) self.__color = background_color - def reset(self): + def reset(self) -> None: self.__surface.fill(self.__color) - def draw_object(self, game_object): + def draw_object(self, game_object: GameObject) -> None: game_object.draw(self.__surface) \ No newline at end of file