diff options
-rwxr-xr-x | cameltris.py | 5 | ||||
-rw-r--r-- | pycameltris/controller.py | 19 | ||||
-rw-r--r-- | pycameltris/screens/InGame.py | 3 | ||||
-rw-r--r-- | pycameltris/screens/Pause.py | 3 | ||||
-rw-r--r-- | pycameltris/screens/Screen.py | 12 |
5 files changed, 37 insertions, 5 deletions
diff --git a/cameltris.py b/cameltris.py index b454db2..50ebb01 100755 --- a/cameltris.py +++ b/cameltris.py @@ -4,7 +4,8 @@ import argparse import pygame -from pycameltris.controller import KeyboardController, JoystickController +from pycameltris.controller import Controller, KeyboardController, JoystickController +from pycameltris.screens.Screen import Screen from pycameltris.screens.InGame import InGame as InGameScreen, Player from pycameltris.screens.Pause import Pause as PauseScreen from pycameltris.misc import Pause, UnPause @@ -23,6 +24,7 @@ pygame.init() screen = pygame.display.set_mode((801, 1000)) +controller: Controller if ARGS["joystick_id"] is not None: joystick = pygame.joystick.Joystick(ARGS["joystick_id"]) joystick.init() @@ -38,6 +40,7 @@ for player in players: clock = pygame.time.Clock() +current_screen: Screen current_screen = ingame_screen = InGameScreen(players, screen) while True: 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 = { diff --git a/pycameltris/screens/InGame.py b/pycameltris/screens/InGame.py index f865c77..aa3e53b 100644 --- a/pycameltris/screens/InGame.py +++ b/pycameltris/screens/InGame.py @@ -5,6 +5,7 @@ import sys import pygame +from .Screen import Screen from ..piece import * from ..controller import Input, KeyboardController, JoystickController from ..misc import Pause @@ -247,7 +248,7 @@ def handle_input_released(instance, players, event): frames_per_gridcell = [48, 43, 38, 33, 28, 23, 18, 13, 8, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1] -class InGame: +class InGame(Screen): def __init__(self, players, screen): self.players = players self.screen = screen diff --git a/pycameltris/screens/Pause.py b/pycameltris/screens/Pause.py index f9f8859..baca5ca 100644 --- a/pycameltris/screens/Pause.py +++ b/pycameltris/screens/Pause.py @@ -3,6 +3,7 @@ import sys import pygame +from .Screen import Screen from ..controller import KeyboardController, JoystickController, Input from ..misc import UnPause @@ -12,7 +13,7 @@ def handle_input_pressed(controller, event): raise UnPause() -class Pause: +class Pause(Screen): def __init__(self, screen): self.event_handler = dict() diff --git a/pycameltris/screens/Screen.py b/pycameltris/screens/Screen.py new file mode 100644 index 0000000..01f80ab --- /dev/null +++ b/pycameltris/screens/Screen.py @@ -0,0 +1,12 @@ +import abc + + +class Screen(abc.ABC): + @abc.abstractmethod + def refresh(self): + pass + + @abc.abstractmethod + def oneframe(self): + pass + |