first test
This commit is contained in:
6
Game.py
6
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())
|
||||
|
||||
|
||||
19
__main__.py
19
__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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
|
||||
Binary file not shown.
@@ -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:
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user