diff --git a/Game.py b/Game.py index 0888dfa..776e16e 100644 --- a/Game.py +++ b/Game.py @@ -3,9 +3,9 @@ import signal class Game: - def __init__(self, input_handler, player_state, game_state): + def __init__(self, input_handler, events, game_state): self.input_handler = input_handler - self.player_state = player_state + self.events = events self.game_state = game_state signal.signal(signal.SIGINT, self.interrupt) self.is_running = asyncio.Condition() @@ -15,7 +15,7 @@ class Game: print('Received SIGINT. Stopping Game :-)') self.is_running.release() - def run(self): + async def run(self): self.is_running.acquire() asyncio.run(self.input_handler.handleInputs()) diff --git a/__main__.py b/__main__.py index 9d06c02..4b614cd 100644 --- a/__main__.py +++ b/__main__.py @@ -1,16 +1,31 @@ +import argparse +import config + from factories.NetworkFactory import NetworkFactory from factories.GameFactory import GameFactory + def main(): args = parseCommandLine() game = createGame(args) game.run() def parseCommandLine(): - return + parser = argparse.ArgumentParser(description='A game for the flippR') + parser.add_argument('-o', '--OutputServerAddress', dest='OutputServerAddress', default=defaultOutputServerAddress()) + parser.add_argument('-i', '--InputServerAddress', dest='InputServerAddress', default=defaultInputServerAddress()) + + return parser.parse_args() + +def defaultOutputServerAddress(): + return config.SOCKET_PATH + config.OUTPUT_SOCKET_NAME + +def defaultInputServerAddress(): + return config.SOCKET_PATH + config.INPUT_SOCKET_NAME def createGame(args): - NetworkFactory.createNetwork(args['OutputServerAddress'], args['InputServerAddress']) + print(args) + NetworkFactory.createNetwork(args.OutputServerAddress, args.InputServerAddress) gameFactory = GameFactory() game = gameFactory.createGame() return game diff --git a/__pycache__/InputHandler.cpython-38.pyc b/__pycache__/InputHandler.cpython-38.pyc index 92b3ecc..e1a6ed6 100644 Binary files a/__pycache__/InputHandler.cpython-38.pyc and b/__pycache__/InputHandler.cpython-38.pyc differ diff --git a/__pycache__/Solenoid.cpython-38.pyc b/__pycache__/Solenoid.cpython-38.pyc index b9250bf..d1722f7 100644 Binary files a/__pycache__/Solenoid.cpython-38.pyc and b/__pycache__/Solenoid.cpython-38.pyc differ diff --git a/__pycache__/__main__.cpython-38.pyc b/__pycache__/__main__.cpython-38.pyc index 48fdb7c..69ef603 100644 Binary files a/__pycache__/__main__.cpython-38.pyc and b/__pycache__/__main__.cpython-38.pyc differ diff --git a/__pycache__/config.cpython-38.pyc b/__pycache__/config.cpython-38.pyc index 7248578..95daaad 100644 Binary files a/__pycache__/config.cpython-38.pyc and b/__pycache__/config.cpython-38.pyc differ diff --git a/config.py b/config.py index 4c726c9..ce29550 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,10 @@ +import os + # Game Config +## Network Config +SOCKET_PATH = os.environ["XDG_RUNTIME_DIR"] if os.environ["XDG_RUNTIME_DIR"] else '/tmp' +INPUT_SOCKET_NAME = "/S.flippR_driver.in" +OUTPUT_SOCKET_NAME = "/S.flippR_driver.out" ## Player State config BALLS_PER_GAME = 3 BEGINNING_UPPER_PLAYFIELD_TIME = 5 diff --git a/displays/__pycache__/Display.cpython-38.pyc b/displays/__pycache__/Display.cpython-38.pyc index 416c9d1..17b1fd2 100644 Binary files a/displays/__pycache__/Display.cpython-38.pyc and b/displays/__pycache__/Display.cpython-38.pyc differ diff --git a/factories/EventFactory.py b/factories/EventFactory.py index 104deaa..06881a6 100644 --- a/factories/EventFactory.py +++ b/factories/EventFactory.py @@ -1,3 +1,5 @@ +import inspect + from events.PointEvent import PointEvent from events.EndOfBallEvent import EndOfBallEvent from events.RightFlapEvent import RightFlapEvent @@ -6,13 +8,23 @@ from events.RightKickerEvent import RightKickerEvent from events.EnterUpperPlayfieldEvent import EnterUpperPlayfieldEvent from events.StartGameEvent import StartGameEvent + class EventFactory: def __init__(self, targets, currentPlayer, upperPlayfieldFlippers, flipper): self.targets = targets self.currentPlayer = currentPlayer self.upperPlayfieldFlippers = upperPlayfieldFlippers self.flipper = flipper - + + def allEvents(self): + methods = inspect.getmembers(self, predicate=inspect.ismethod) + createMethods = [method[1] for method in methods if 'create' in method] + result = [] + for method in createMethods: + result.append(method()) + + return result + def createPointEvent(self): event = PointEvent(self.currentPlayer) for target in self.targets: diff --git a/factories/GameFactory.py b/factories/GameFactory.py index 6fc4f12..cc3ff27 100644 --- a/factories/GameFactory.py +++ b/factories/GameFactory.py @@ -10,6 +10,7 @@ from InputHandler import InputHandler from GameState import GameState +from Game import Game class GameFactory: def __init__(self): @@ -31,8 +32,9 @@ class GameFactory: gameState = GameState(players, self.getHighScore(), players[0].id) eventFactory = EventFactory(targets, gameState.currentPlayer) - pointEvent = eventFactory.createPointEvent() + events = eventFactory.allEvents() + return Game(inputHandler, gameState, events) def createPlayers(self): players = [] diff --git a/factories/__pycache__/EventFactory.cpython-38.pyc b/factories/__pycache__/EventFactory.cpython-38.pyc index da0ca17..72b2deb 100644 Binary files a/factories/__pycache__/EventFactory.cpython-38.pyc and b/factories/__pycache__/EventFactory.cpython-38.pyc differ diff --git a/factories/__pycache__/GameFactory.cpython-38.pyc b/factories/__pycache__/GameFactory.cpython-38.pyc index 89e757f..a36b2c2 100644 Binary files a/factories/__pycache__/GameFactory.cpython-38.pyc and b/factories/__pycache__/GameFactory.cpython-38.pyc differ