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