Add type annotations.

This commit is contained in:
paulusja 2026-04-16 16:16:50 +02:00
parent 3c64cf8228
commit 30c4773f13
4 changed files with 9 additions and 7 deletions

View File

@ -4,7 +4,7 @@ import pygame
class InputManager: class InputManager:
QUIT = 0 QUIT = 0
def process_input(self): def process_input(self) -> int:
last_input = None last_input = None
for event in pygame.event.get(): for event in pygame.event.get():

View File

@ -2,8 +2,9 @@ import pygame
from window import Window from window import Window
from input_manager import InputManager from input_manager import InputManager
from snake import Snake 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() window.reset()
for obj in game_objs: for obj in game_objs:

View File

@ -3,12 +3,12 @@ from game_object import GameObject
class Snake(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.__pos = start_position
self.__radius = radius self.__radius = radius
self.__color = color self.__color = color
def draw(self, surface): def draw(self, surface: pygame.Surface) -> None:
pygame.draw.circle(surface=surface, pygame.draw.circle(surface=surface,
color=self.__color, color=self.__color,
center=self.__pos, center=self.__pos,

View File

@ -1,18 +1,19 @@
import pygame import pygame
from game_object import GameObject
class Window: 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.init()
pygame.display.set_caption(title) pygame.display.set_caption(title)
self.__surface = pygame.display.set_mode(size=size) self.__surface = pygame.display.set_mode(size=size)
self.__color = background_color self.__color = background_color
def reset(self): def reset(self) -> None:
self.__surface.fill(self.__color) self.__surface.fill(self.__color)
def draw_object(self, game_object): def draw_object(self, game_object: GameObject) -> None:
game_object.draw(self.__surface) game_object.draw(self.__surface)