diff --git a/snake/input_manager.py b/snake/input_manager.py new file mode 100644 index 0000000..33244b1 --- /dev/null +++ b/snake/input_manager.py @@ -0,0 +1,10 @@ +import pygame + + +class InputManager: + QUIT = 0 + + def process_input(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + return InputManager.QUIT \ No newline at end of file diff --git a/snake/main.py b/snake/main.py index 843363e..efebd99 100644 --- a/snake/main.py +++ b/snake/main.py @@ -1,19 +1,19 @@ import pygame from window import Window +from input_manager import InputManager if __name__ == '__main__': window = Window(title='Snake', size=(800, 600), background_color=(0, 128, 0)) + input_manager = InputManager() clock = pygame.time.Clock() framerate = 25 - shall_abort = False + last_input = None - while not shall_abort: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - shall_abort = True + while last_input != InputManager.QUIT: + last_input = input_manager.process_input() window.reset()