From 1fe19d3e589bbc5d40b74d007d6b1984cfc34925 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Mon, 8 Nov 2021 17:53:17 +0100 Subject: Make controller classes and screen classes inherit from abstract classes Signed-off-by: Olivier Gayot --- pycameltris/controller.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'pycameltris/controller.py') diff --git a/pycameltris/controller.py b/pycameltris/controller.py index 9878536..86f5bcb 100644 --- a/pycameltris/controller.py +++ b/pycameltris/controller.py @@ -1,3 +1,4 @@ +import abc import enum import pygame @@ -13,7 +14,21 @@ class Input(enum.Enum): QUIT = 6 -class JoystickController: +class Controller(abc.ABC): + @abc.abstractmethod + def is_pressed(self, input_: Input): + pass + + @abc.abstractmethod + def get_input_down(self, event): + pass + + @abc.abstractmethod + def get_input_up(self, event): + pass + + +class JoystickController(Controller): class PS3Controller(enum.Enum): CROSS = 0 @@ -57,7 +72,7 @@ class JoystickController: return None -class KeyboardController: +class KeyboardController(Controller): def __init__(self, keyboard): self.keyboard = keyboard self.mapping = { -- cgit v1.2.3