thiiiiings
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
import asyncio
|
||||||
|
import signal
|
||||||
|
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
def __init__(self, input_handler, player_state, game_state):
|
||||||
|
self.input_handler = input_handler
|
||||||
|
self.player_state = player_state
|
||||||
|
self.game_state = game_state
|
||||||
|
signal.signal(signal.SIGINT, self.interrupt)
|
||||||
|
self.is_running = asyncio.Condition()
|
||||||
|
pass
|
||||||
|
|
||||||
|
def interrupt(self):
|
||||||
|
print('Received SIGINT. Stopping Game :-)')
|
||||||
|
self.is_running.release()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.is_running.acquire()
|
||||||
|
asyncio.run(self.input_handler.handleInputs())
|
||||||
|
|
||||||
|
await self.is_running.wait()
|
||||||
|
pass
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
class GameState:
|
||||||
|
def __init__(self, players, highscore, currentPlayer = 1):
|
||||||
|
self.players = players
|
||||||
|
self.currentPlayer = currentPlayer
|
||||||
|
self.highscore = highscore
|
||||||
|
|
||||||
|
def currentPlayer(self):
|
||||||
|
return self.players[0]
|
||||||
|
|
||||||
|
def setCurrentPlayer(self, playerId):
|
||||||
|
if(playerId > len(self.players)):
|
||||||
|
pass # todo throw error
|
||||||
|
|
||||||
|
savedPlayer = self.players[0]
|
||||||
|
self.players[0] = filter(lambda x: playerId == x.id, self.players)
|
||||||
|
self.players.remove(savedPlayer)
|
||||||
|
self.players.append(savedPlayer)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import asyncio
|
||||||
|
from networking.Networking import Networking
|
||||||
|
|
||||||
|
|
||||||
|
class InputHandler:
|
||||||
|
def __init__(self, targets):
|
||||||
|
self.isRunning = True
|
||||||
|
self.targets = targets
|
||||||
|
|
||||||
|
async def handleInputs(self):
|
||||||
|
self.isRunning = True
|
||||||
|
while self.isRunning:
|
||||||
|
event = await Networking().getInputEvent()
|
||||||
|
self.targets[event].hit() #Todo
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.isRunning = False
|
||||||
@@ -15,15 +15,15 @@ class PlayerState:
|
|||||||
|
|
||||||
def addPoints(self, points):
|
def addPoints(self, points):
|
||||||
self.__points += points
|
self.__points += points
|
||||||
self.display.write_score(self.__points)
|
self.display.printScore(self.__points)
|
||||||
|
|
||||||
def addBall(self):
|
def addBall(self):
|
||||||
self.ballsLeft += 1
|
self.ballsLeft += 1
|
||||||
self.specialDisplay.write_ballsToPlay(self.ballsLeft)
|
self.specialDisplay.printBallsToPlay(self.ballsLeft)
|
||||||
|
|
||||||
def removeBall(self):
|
def removeBall(self):
|
||||||
self.ballsLeft -= 1
|
self.ballsLeft -= 1
|
||||||
self.specialDisplay.write_ballsToPlay(self.ballsLeft)
|
self.specialDisplay.printBallsToPlay(self.ballsLeft)
|
||||||
if(self.ballsLeft == 0):
|
if(self.ballsLeft == 0):
|
||||||
# todo emit endgame Event
|
# todo emit endgame Event
|
||||||
pass
|
pass
|
||||||
@@ -39,7 +39,7 @@ class PlayerState:
|
|||||||
self.timer = Timer(self.upperPlayfieldTime, self.stopUpperPlayfieldTimer)
|
self.timer = Timer(self.upperPlayfieldTime, self.stopUpperPlayfieldTimer)
|
||||||
|
|
||||||
def stopUpperPlayfieldTimer(self):
|
def stopUpperPlayfieldTimer(self):
|
||||||
if(self.timer == None):
|
if not self.timer:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.timer.cancel()
|
self.timer.cancel()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from src.networking.Networking import Networking
|
from networking.Networking import Networking
|
||||||
from src.utils.util import normalizeName
|
from utils.util import normalizeName
|
||||||
|
|
||||||
class Solenoid:
|
class Solenoid:
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
@@ -11,4 +11,4 @@ class Solenoid:
|
|||||||
self.name = normalizeName(solenoidName)
|
self.name = normalizeName(solenoidName)
|
||||||
|
|
||||||
def trigger(self):
|
def trigger(self):
|
||||||
Networking.triggerSolenoid(self.name)
|
Networking().triggerSolenoid(self.name)
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
from factories.NetworkFactory import NetworkFactory
|
||||||
|
from factories.GameFactory import GameFactory
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = parseCommandLine()
|
||||||
|
game = createGame(args)
|
||||||
|
game.run()
|
||||||
|
|
||||||
|
def parseCommandLine():
|
||||||
|
return
|
||||||
|
|
||||||
|
def createGame(args):
|
||||||
|
NetworkFactory.createNetwork(args['OutputServerAddress'], args['InputServerAddress'])
|
||||||
|
gameFactory = GameFactory()
|
||||||
|
game = gameFactory.createGame()
|
||||||
|
return game
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
from networking.Networking import Networking
|
||||||
|
|
||||||
|
|
||||||
|
class Display:
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def printScore(self, score):
|
||||||
|
Networking().write(self.name, score)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.displays.Display import Display
|
from displays.Display import Display
|
||||||
|
|
||||||
class PlayerDisplay(Display):
|
class PlayerDisplay(Display):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.displays.Display import Display
|
from displays.Display import Display
|
||||||
|
|
||||||
class SpecialDisplay(Display):
|
class SpecialDisplay(Display):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
@@ -7,19 +7,19 @@ class SpecialDisplay(Display):
|
|||||||
self.gameTimeBonus = 0
|
self.gameTimeBonus = 0
|
||||||
self.ballsToPlay = 0
|
self.ballsToPlay = 0
|
||||||
|
|
||||||
def write_score(self):
|
def printScore(self):
|
||||||
super.write_score(int(str(self.credits).zfill(2)
|
super.write_score(int(str(self.credits).zfill(2)
|
||||||
+ str(self.gameTimeBonus).zfill(2)
|
+ str(self.gameTimeBonus).zfill(2)
|
||||||
+ str(self.ballsToPlay).zfill(2)))
|
+ str(self.ballsToPlay).zfill(2)))
|
||||||
|
|
||||||
def write_ballsToPlay(self, ballsToPlay):
|
def printBallsToPlay(self, ballsToPlay):
|
||||||
self.ballsToPlay = ballsToPlay
|
self.ballsToPlay = ballsToPlay
|
||||||
self.write_score()
|
self.printScore()
|
||||||
|
|
||||||
def write_gameTimeBonus(self, gameTimeBonus):
|
def printGameTimeBonus(self, gameTimeBonus):
|
||||||
self.gameTimeBonus = gameTimeBonus
|
self.gameTimeBonus = gameTimeBonus
|
||||||
self.write_score()
|
self.printScore()
|
||||||
|
|
||||||
def write_credits(self, credits):
|
def printCredits(self, credits):
|
||||||
self.credits = credits
|
self.credits = credits
|
||||||
self.write_score()
|
self.printScore()
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -3,4 +3,4 @@ class BonusTimeEvent:
|
|||||||
self.playerState = playerState
|
self.playerState = playerState
|
||||||
|
|
||||||
def trigger(self):
|
def trigger(self):
|
||||||
self.playerState.addBonusTimeSecond()
|
self.playerState().addBonusTimeSecond()
|
||||||
@@ -3,4 +3,4 @@ class EndOfBallEvent:
|
|||||||
self.playerState = playerState
|
self.playerState = playerState
|
||||||
|
|
||||||
def trigger(self):
|
def trigger(self):
|
||||||
self.playerState.removeBall()
|
self.playerState().removeBall()
|
||||||
@@ -5,4 +5,4 @@ class EnterUpperPlayfieldEvent:
|
|||||||
|
|
||||||
def trigger(self):
|
def trigger(self):
|
||||||
self.flipper.activate()
|
self.flipper.activate()
|
||||||
self.playerState.startUpperPlayfieldTimer()
|
self.playerState().startUpperPlayfieldTimer()
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class FlapEvent:
|
||||||
|
def __init__(self, flapSolenoid):
|
||||||
|
self.flapSolenoid = flapSolenoid
|
||||||
|
|
||||||
|
def trigger(self):
|
||||||
|
self.flapSolenoid.trigger()
|
||||||
@@ -5,4 +5,4 @@ class LeaveUpperPlayfieldEvent:
|
|||||||
|
|
||||||
def trigger(self):
|
def trigger(self):
|
||||||
self.flipper.deactivate()
|
self.flipper.deactivate()
|
||||||
self.playerState.stopUpperPlayfieldTimer()
|
self.playerState().stopUpperPlayfieldTimer()
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from events.FlapEvent import FlapEvent
|
||||||
|
from solenoids.LeftFlapSolenoid import LeftFlapSolenoid
|
||||||
|
|
||||||
|
|
||||||
|
class LeftFlapEvent(FlapEvent):
|
||||||
|
def __init__(self):
|
||||||
|
super(LeftFlapSolenoid())
|
||||||
@@ -3,4 +3,4 @@ class PointEvent:
|
|||||||
self.playerState = playerState
|
self.playerState = playerState
|
||||||
|
|
||||||
def trigger(self, target):
|
def trigger(self, target):
|
||||||
self.playerState.addPoints(target.points)
|
self.playerState().addPoints(target.points)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from events.FlapEvent import FlapEvent
|
||||||
|
from solenoids.RightFlapSolenoid import RightFlapSolenoid
|
||||||
|
|
||||||
|
|
||||||
|
class RightFlapEvent(FlapEvent):
|
||||||
|
def __init__(self):
|
||||||
|
super(RightFlapSolenoid())
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from solenoids.RightKickerSolenoid import RightKickerSolenoid
|
||||||
|
|
||||||
|
|
||||||
|
class RightKickerEvent:
|
||||||
|
def __init__(self):
|
||||||
|
self.rightKickerSolenoid = RightKickerSolenoid()
|
||||||
|
|
||||||
|
def trigger(self):
|
||||||
|
self.rightKickerSolenoid.trigger()
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
from solenoids.OutHoleSolenoid import OutHoleSolenoid
|
||||||
|
|
||||||
|
class StartGameEvent:
|
||||||
|
def __init__(self, flipper):
|
||||||
|
self.flipper = flipper
|
||||||
|
self.outHoleSolenoid = OutHoleSolenoid()
|
||||||
|
|
||||||
|
def trigger(self):
|
||||||
|
self.flipper.activate()
|
||||||
|
self.outHoleSolenoid.trigger()
|
||||||
@@ -3,4 +3,4 @@ class UpperPlayfieldTimeEvent:
|
|||||||
self.playerState = playerState
|
self.playerState = playerState
|
||||||
|
|
||||||
def trigger(self):
|
def trigger(self):
|
||||||
self.playerState.addUpperPlayfieldTime(1)
|
self.playerState().addUpperPlayfieldTime(1)
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,14 @@
|
|||||||
|
from displays.PlayerDisplay import PlayerDisplay
|
||||||
|
from displays.SpecialDisplay import SpecialDisplay
|
||||||
|
|
||||||
|
class DisplayFactory:
|
||||||
|
def __init__(self, displayNames):
|
||||||
|
self.displayNames = displayNames
|
||||||
|
|
||||||
|
def createSpecialDisplay(self):
|
||||||
|
name = filter(lambda displayName: "Special" in displayName, self.displayNames)
|
||||||
|
return SpecialDisplay(name)
|
||||||
|
|
||||||
|
def createPlayerDisplay(self, id):
|
||||||
|
name = filter(lambda displayName: "Player" in displayName and str(id) in displayName, self.displayNames)
|
||||||
|
return PlayerDisplay(name)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
from events.PointEvent import PointEvent
|
||||||
|
from events.EndOfBallEvent import EndOfBallEvent
|
||||||
|
from events.RightFlapEvent import RightFlapEvent
|
||||||
|
from events.LeftFlapEvent import LeftFlapEvent
|
||||||
|
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 createPointEvent(self):
|
||||||
|
event = PointEvent(self.currentPlayer)
|
||||||
|
for target in self.targets:
|
||||||
|
self.__registerEventToTarget(event, target)
|
||||||
|
return event
|
||||||
|
|
||||||
|
def createEndOfBallEvent(self):
|
||||||
|
event = EndOfBallEvent(self.currentPlayer)
|
||||||
|
self.__registerEventToTarget(event, self.targets['OutholeTarget'])
|
||||||
|
return event
|
||||||
|
|
||||||
|
def createRightFlapEvent(self):
|
||||||
|
event = RightFlapEvent()
|
||||||
|
self.__registerEventToTarget(event, self.targets['RightSlingshotTarget'])
|
||||||
|
return event
|
||||||
|
|
||||||
|
def createLeftFlapEvent(self):
|
||||||
|
event = LeftFlapEvent()
|
||||||
|
self.__registerEventToTarget(event, self.targets['LeftSlingshotTarget'])
|
||||||
|
return event
|
||||||
|
|
||||||
|
def createRightKickerEvent(self):
|
||||||
|
event = RightKickerEvent()
|
||||||
|
self.__registerEventToTarget(event, self.targets['RightOutlaneKickerTarget'])
|
||||||
|
return event
|
||||||
|
|
||||||
|
def createEnterUpperPlayfieldEvent(self):
|
||||||
|
event = EnterUpperPlayfieldEvent(self.currentPlayer, self.upperPlayfieldFlippers)
|
||||||
|
self.__registerEventToTarget(event, self.targets['UpperPlayfieldRollUnderTarget'])
|
||||||
|
return event
|
||||||
|
|
||||||
|
def createStartGameEvent(self):
|
||||||
|
event = StartGameEvent(self.flipper)
|
||||||
|
self.__registerEventToTarget(event, self.targets['CreditTarget'])
|
||||||
|
return event
|
||||||
|
|
||||||
|
def __registerEventToTarget(self, event, target):
|
||||||
|
target.on(target.hit_key, event.trigger)
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
from config import *
|
||||||
|
from networking.Networking import Networking
|
||||||
|
|
||||||
|
from factories.PlayerStateFactory import PlayerStateFactory
|
||||||
|
from factories.DisplayFactory import DisplayFactory
|
||||||
|
from factories.TargetFactory import TargetFactory
|
||||||
|
from factories.EventFactory import EventFactory
|
||||||
|
|
||||||
|
from InputHandler import InputHandler
|
||||||
|
|
||||||
|
from GameState import GameState
|
||||||
|
|
||||||
|
|
||||||
|
class GameFactory:
|
||||||
|
def __init__(self):
|
||||||
|
displayNames = Networking().getDisplays()
|
||||||
|
self.displayFactory = DisplayFactory(displayNames)
|
||||||
|
specialDisplay = self.displayFactory.createSpecialDisplay()
|
||||||
|
|
||||||
|
self.playerCount = len(displayNames) - 1
|
||||||
|
|
||||||
|
self.playerStateFactory = PlayerStateFactory(specialDisplay)
|
||||||
|
|
||||||
|
|
||||||
|
def createGame(self):
|
||||||
|
targets = TargetFactory.createAllTargets()
|
||||||
|
inputHandler = InputHandler(targets)
|
||||||
|
|
||||||
|
players = self.createPlayers()
|
||||||
|
|
||||||
|
gameState = GameState(players, self.getHighScore(), players[0].id)
|
||||||
|
|
||||||
|
eventFactory = EventFactory(targets, gameState.currentPlayer)
|
||||||
|
pointEvent = eventFactory.createPointEvent()
|
||||||
|
|
||||||
|
|
||||||
|
def createPlayers(self):
|
||||||
|
players = []
|
||||||
|
for id in range(self.playerCount):
|
||||||
|
display = self.displayFactory.createPlayerDisplay(id)
|
||||||
|
player = self.playerStateFactory.createPlayerState(display, id)
|
||||||
|
players.append(player)
|
||||||
|
return players
|
||||||
|
|
||||||
|
def getHighScore(self): # todo
|
||||||
|
return 0
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from networking.Networking import Networking
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkFactory:
|
||||||
|
@staticmethod
|
||||||
|
def createNetwork(output_server_address, input_server_address):
|
||||||
|
Networking(output_server_address, input_server_address)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from config import *
|
||||||
|
from PlayerState import PlayerState
|
||||||
|
|
||||||
|
class PlayerStateFactory:
|
||||||
|
def __init__(self, specialDisplay):
|
||||||
|
self.specialDisplay = specialDisplay
|
||||||
|
|
||||||
|
def createPlayerState(self, display, id):
|
||||||
|
return PlayerState(display, self.specialDisplay, id, BALLS_PER_GAME, BEGINNING_UPPER_PLAYFIELD_TIME, BEGINNING_BONUS_TIME)
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
from targets import *
|
||||||
|
from targets.BankTarget import BankTarget
|
||||||
|
|
||||||
|
class TargetFactory:
|
||||||
|
def createAllTargets(self):
|
||||||
|
result = dict()
|
||||||
|
glo = globals() # Save globals so the dict does not change during execution of the script
|
||||||
|
|
||||||
|
for key in glo:
|
||||||
|
if(type(target) != 'class'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
target = glo[key]
|
||||||
|
if 'Target' in key:
|
||||||
|
result[key] = target()
|
||||||
|
elif 'Bank' in key and 'Target' not in key:
|
||||||
|
targets = self.createBankTarget(target, key)
|
||||||
|
result = {**result, **targets}
|
||||||
|
# todo check with driver?
|
||||||
|
return result
|
||||||
|
|
||||||
|
def createBankTarget(self, target, key):
|
||||||
|
bankTarget = target()
|
||||||
|
targets = dict()
|
||||||
|
targets[key] = bankTarget
|
||||||
|
|
||||||
|
for target in bankTarget.targets:
|
||||||
|
name = type(target).__name__
|
||||||
|
targets[name] = target
|
||||||
|
|
||||||
|
return targets
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
import requests_unixsocket as req
|
import requests_unixsocket as req
|
||||||
import socket
|
import socket
|
||||||
from src.utils.Singleton import Singleton
|
from utils.Singleton import Singleton
|
||||||
|
|
||||||
|
|
||||||
class Networking(metaclass=Singleton):
|
class Networking(metaclass=Singleton):
|
||||||
@@ -47,7 +47,7 @@ class Networking(metaclass=Singleton):
|
|||||||
def writeDisplayScore(self, display, score):
|
def writeDisplayScore(self, display, score):
|
||||||
self.get("/displays/" + display + "/write_score/" + str(score))
|
self.get("/displays/" + display + "/write_score/" + str(score))
|
||||||
|
|
||||||
def getInputEvent(self):
|
async def getInputEvent(self):
|
||||||
header = list()
|
header = list()
|
||||||
while b'\x02' not in header:
|
while b'\x02' not in header:
|
||||||
byte = self.input_socket.recv(1)
|
byte = self.input_socket.recv(1)
|
||||||
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class BottomLeftBankSolenoid(Solenoid):
|
class BottomLeftBankSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class BottomRightBankSolenoid(Solenoid):
|
class BottomRightBankSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class BottomRightPopSolenoid(Solenoid):
|
class BottomRightPopSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class CoinMechanismCoilSolenoid(Solenoid):
|
class CoinMechanismCoilSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class KnockerSolenoid(Solenoid):
|
class KnockerSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class LeftFlapSolenoid(Solenoid):
|
class LeftFlapSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class OutHoleSolenoid(Solenoid):
|
class OutHoleSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class RightFlapSolenoid(Solenoid):
|
class RightFlapSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class RightKickerSolenoid(Solenoid):
|
class RightKickerSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class TopCentralBankSolenoid(Solenoid):
|
class TopCentralBankSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.Solenoid import Solenoid
|
from Solenoid import Solenoid
|
||||||
|
|
||||||
class TopLeftPopSolenoid(Solenoid):
|
class TopLeftPopSolenoid(Solenoid):
|
||||||
pass
|
pass
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +0,0 @@
|
|||||||
class GameState:
|
|
||||||
def __init__(self, players):
|
|
||||||
self.players = players
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import asyncio
|
|
||||||
from src.networking.Networking import Networking
|
|
||||||
|
|
||||||
|
|
||||||
class EventHandler:
|
|
||||||
def __init__(self, targets):
|
|
||||||
self.isRunning = True
|
|
||||||
self.targets = targets
|
|
||||||
|
|
||||||
async def handleEvents(self):
|
|
||||||
self.isRunning = True
|
|
||||||
while(self.isRunning):
|
|
||||||
event = Networking.getInputEvent()
|
|
||||||
self.targets[event].hit()
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
self.isRunning = False
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
from src.networking.Networking import Networking
|
|
||||||
|
|
||||||
|
|
||||||
class Display:
|
|
||||||
def __init__(self, name):
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
def write_score(self, score):
|
|
||||||
Networking.write(self.name, score)
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
from src.events.FlapEvent import FlapEvent
|
|
||||||
from src.solenoids.RightFlapSolenoid import RightFlapSolenoid
|
|
||||||
|
|
||||||
|
|
||||||
class RightFlapEvent(FlapEvent):
|
|
||||||
def __init__(self):
|
|
||||||
super(RightFlapSolenoid())
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
class StartGameEvent:
|
|
||||||
def __init__(self, flipper):
|
|
||||||
self.flipper = flipper
|
|
||||||
|
|
||||||
def trigger(self):
|
|
||||||
flipper.activate()
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
from src.config import *
|
|
||||||
from src.networking.Networking import Networking
|
|
||||||
|
|
||||||
from src.PlayerState import PlayerState
|
|
||||||
|
|
||||||
from src.displays.PlayerDisplay import PlayerDisplay
|
|
||||||
from src.displays.SpecialDisplay import SpecialDisplay
|
|
||||||
|
|
||||||
from src.EventHandler import EventHandler
|
|
||||||
from src.targets import *
|
|
||||||
|
|
||||||
from src.events.PointEvent import PointEvent
|
|
||||||
|
|
||||||
class GameFactory:
|
|
||||||
def createGame(self):
|
|
||||||
targets = self.createAllTargets()
|
|
||||||
eventHandler = EventHandler(targets)
|
|
||||||
|
|
||||||
displayNames = Networking.getDisplays()
|
|
||||||
playerDisplays = self.createPlayerDisplays(displayNames)
|
|
||||||
|
|
||||||
playerState = PlayerState()
|
|
||||||
pointEvent = PointEvent()
|
|
||||||
for target in self.targets:
|
|
||||||
target.on(target.hit_key,
|
|
||||||
pass
|
|
||||||
|
|
||||||
def createPlayerDisplays(self, displayNames):
|
|
||||||
result = []
|
|
||||||
for displayName in displayNames:
|
|
||||||
if("Player" in displayName):
|
|
||||||
display = PlayerDisplay(displayName)
|
|
||||||
result.append(display)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def createPlayerStates(self, playerDisplays, specialDisplay, ballsPerGame = BALLS_PER_GAME, beginningUpperPlayfieldTime = BEGINNING_UPPER_PLAYFIELD_TIME, beginningBonusTime = BEGINNING_BONUS_TIME):
|
|
||||||
result = []
|
|
||||||
for i in range(len(playerDisplays)):
|
|
||||||
playerState = PlayerState(playerDisplays[i], specialDisplay, i, ballsPerGame, beginningUpperPlayfieldTime, beginningBonusTime)
|
|
||||||
result.append(playerState)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def createAllTargets(self):
|
|
||||||
result = dict
|
|
||||||
glo = globals() # Save globals so the dict does not change during execution of the script
|
|
||||||
for key in glo:
|
|
||||||
target = glo[key]
|
|
||||||
if(key.endswith('Target') and type(target) == 'class'):
|
|
||||||
result[key] = target()
|
|
||||||
# todo check with driver?
|
|
||||||
return result
|
|
||||||
-46
@@ -1,46 +0,0 @@
|
|||||||
output_server_address = ''
|
|
||||||
input_server_address = ''
|
|
||||||
|
|
||||||
#network = Networking(output_server_address, input_server_address)
|
|
||||||
network = ''
|
|
||||||
|
|
||||||
class EventHandler():
|
|
||||||
def __init__(self, network):
|
|
||||||
# brace yourselves, python incoming
|
|
||||||
self.subclasses = {subcls.__name__: subcls for subcls in self.__class__.__subclasses__()}
|
|
||||||
self.network = network
|
|
||||||
|
|
||||||
def handle(self, name):
|
|
||||||
self.subclasses[name](network)
|
|
||||||
|
|
||||||
class LeftFlapEventHandler(EventHandler):
|
|
||||||
def __init__(self, network):
|
|
||||||
print('Left Flap Event gets handled')
|
|
||||||
self.handle()
|
|
||||||
|
|
||||||
def handle(self):
|
|
||||||
# do stuff...
|
|
||||||
pass
|
|
||||||
|
|
||||||
class GameState:
|
|
||||||
def __init__(self, targets):
|
|
||||||
self.score = 0
|
|
||||||
self.targets = targets
|
|
||||||
for target in self.targets:
|
|
||||||
target.on(target.hit_key, self.__target_hit__)
|
|
||||||
|
|
||||||
def __target_hit__(self, target):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def snake_to_camel(word):
|
|
||||||
return ''.join(x.capitalize() or '' for x in word.split('_'))
|
|
||||||
|
|
||||||
handler = EventHandler(network)
|
|
||||||
handler.handle(snake_to_camel('left_flap') + 'EventHandler')
|
|
||||||
|
|
||||||
# while True:
|
|
||||||
# event_name = snake_to_camel(network.getInputEvent())
|
|
||||||
# handler.handle(event_name + 'EventHandler')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,12 +0,0 @@
|
|||||||
from src.targets.Bank import Bank
|
|
||||||
from src.targets.right_bank import RightBankLeft
|
|
||||||
from src.targets.right_bank import RightBankMiddle
|
|
||||||
from src.targets.right_bank import RightBankRight
|
|
||||||
|
|
||||||
class RightBank(Bank):
|
|
||||||
def __init__(self):
|
|
||||||
targets = [RightBankLeft(), RightBankMiddle(), RightBankRight]
|
|
||||||
super(0, "Right Bank", targets)
|
|
||||||
|
|
||||||
def hit(self):
|
|
||||||
super.hit()
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.targets.Target import Target
|
from targets.Target import Target
|
||||||
|
|
||||||
class Bank(Target):
|
class Bank(Target):
|
||||||
def __init__(self, points, name, targets):
|
def __init__(self, points, name, targets):
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.targets.Target import Target
|
from targets.Target import Target
|
||||||
|
|
||||||
class BankTarget(Target):
|
class BankTarget(Target):
|
||||||
def __init__(self, points):
|
def __init__(self, points):
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from src.targets.Target import Target
|
from targets.Target import Target
|
||||||
|
|
||||||
class ReboundContactTarget(Target):
|
class ReboundContactTarget(Target):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
from src.targets.Target import Target
|
from targets.Target import Target
|
||||||
|
|
||||||
class LeftInlaneTarget(Target):
|
class LeftInlaneTarget(Target):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
from src.targets.Target import Target
|
from targets.Target import Target
|
||||||
|
|
||||||
class LeftOutlaneTarget(Target):
|
class LeftOutlaneTarget(Target):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
from src.targets.Target import Target
|
from targets.Target import Target
|
||||||
|
|
||||||
|
|
||||||
class RightInlaneTarget(Target):
|
class RightInlaneTarget(Target):
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
from src.targets.Target import Target
|
from targets.Target import Target
|
||||||
|
|
||||||
|
|
||||||
class RightOutlaneKickerTarget(Target):
|
class RightOutlaneKickerTarget(Target):
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user