Add type annotations.
This commit is contained in:
parent
3c64cf8228
commit
30c4773f13
@ -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():
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user