first test
This commit is contained in:
6
Game.py
6
Game.py
@@ -3,9 +3,9 @@ import signal
|
|||||||
|
|
||||||
|
|
||||||
class Game:
|
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.input_handler = input_handler
|
||||||
self.player_state = player_state
|
self.events = events
|
||||||
self.game_state = game_state
|
self.game_state = game_state
|
||||||
signal.signal(signal.SIGINT, self.interrupt)
|
signal.signal(signal.SIGINT, self.interrupt)
|
||||||
self.is_running = asyncio.Condition()
|
self.is_running = asyncio.Condition()
|
||||||
@@ -15,7 +15,7 @@ class Game:
|
|||||||
print('Received SIGINT. Stopping Game :-)')
|
print('Received SIGINT. Stopping Game :-)')
|
||||||
self.is_running.release()
|
self.is_running.release()
|
||||||
|
|
||||||
def run(self):
|
async def run(self):
|
||||||
self.is_running.acquire()
|
self.is_running.acquire()
|
||||||
asyncio.run(self.input_handler.handleInputs())
|
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.NetworkFactory import NetworkFactory
|
||||||
from factories.GameFactory import GameFactory
|
from factories.GameFactory import GameFactory
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parseCommandLine()
|
args = parseCommandLine()
|
||||||
game = createGame(args)
|
game = createGame(args)
|
||||||
game.run()
|
game.run()
|
||||||
|
|
||||||
def parseCommandLine():
|
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):
|
def createGame(args):
|
||||||
NetworkFactory.createNetwork(args['OutputServerAddress'], args['InputServerAddress'])
|
print(args)
|
||||||
|
NetworkFactory.createNetwork(args.OutputServerAddress, args.InputServerAddress)
|
||||||
gameFactory = GameFactory()
|
gameFactory = GameFactory()
|
||||||
game = gameFactory.createGame()
|
game = gameFactory.createGame()
|
||||||
return game
|
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
|
# 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
|
## Player State config
|
||||||
BALLS_PER_GAME = 3
|
BALLS_PER_GAME = 3
|
||||||
BEGINNING_UPPER_PLAYFIELD_TIME = 5
|
BEGINNING_UPPER_PLAYFIELD_TIME = 5
|
||||||
|
|||||||
Binary file not shown.
@@ -1,3 +1,5 @@
|
|||||||
|
import inspect
|
||||||
|
|
||||||
from events.PointEvent import PointEvent
|
from events.PointEvent import PointEvent
|
||||||
from events.EndOfBallEvent import EndOfBallEvent
|
from events.EndOfBallEvent import EndOfBallEvent
|
||||||
from events.RightFlapEvent import RightFlapEvent
|
from events.RightFlapEvent import RightFlapEvent
|
||||||
@@ -6,6 +8,7 @@ from events.RightKickerEvent import RightKickerEvent
|
|||||||
from events.EnterUpperPlayfieldEvent import EnterUpperPlayfieldEvent
|
from events.EnterUpperPlayfieldEvent import EnterUpperPlayfieldEvent
|
||||||
from events.StartGameEvent import StartGameEvent
|
from events.StartGameEvent import StartGameEvent
|
||||||
|
|
||||||
|
|
||||||
class EventFactory:
|
class EventFactory:
|
||||||
def __init__(self, targets, currentPlayer, upperPlayfieldFlippers, flipper):
|
def __init__(self, targets, currentPlayer, upperPlayfieldFlippers, flipper):
|
||||||
self.targets = targets
|
self.targets = targets
|
||||||
@@ -13,6 +16,15 @@ class EventFactory:
|
|||||||
self.upperPlayfieldFlippers = upperPlayfieldFlippers
|
self.upperPlayfieldFlippers = upperPlayfieldFlippers
|
||||||
self.flipper = flipper
|
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):
|
def createPointEvent(self):
|
||||||
event = PointEvent(self.currentPlayer)
|
event = PointEvent(self.currentPlayer)
|
||||||
for target in self.targets:
|
for target in self.targets:
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from InputHandler import InputHandler
|
|||||||
|
|
||||||
from GameState import GameState
|
from GameState import GameState
|
||||||
|
|
||||||
|
from Game import Game
|
||||||
|
|
||||||
class GameFactory:
|
class GameFactory:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -31,8 +32,9 @@ class GameFactory:
|
|||||||
gameState = GameState(players, self.getHighScore(), players[0].id)
|
gameState = GameState(players, self.getHighScore(), players[0].id)
|
||||||
|
|
||||||
eventFactory = EventFactory(targets, gameState.currentPlayer)
|
eventFactory = EventFactory(targets, gameState.currentPlayer)
|
||||||
pointEvent = eventFactory.createPointEvent()
|
events = eventFactory.allEvents()
|
||||||
|
|
||||||
|
return Game(inputHandler, gameState, events)
|
||||||
|
|
||||||
def createPlayers(self):
|
def createPlayers(self):
|
||||||
players = []
|
players = []
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user