thiiiiings
This commit is contained in:
23
Game.py
Normal file
23
Game.py
Normal file
@@ -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
|
||||
17
GameState.py
Normal file
17
GameState.py
Normal file
@@ -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)
|
||||
17
InputHandler.py
Normal file
17
InputHandler.py
Normal file
@@ -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):
|
||||
self.__points += points
|
||||
self.display.write_score(self.__points)
|
||||
self.display.printScore(self.__points)
|
||||
|
||||
def addBall(self):
|
||||
self.ballsLeft += 1
|
||||
self.specialDisplay.write_ballsToPlay(self.ballsLeft)
|
||||
self.specialDisplay.printBallsToPlay(self.ballsLeft)
|
||||
|
||||
def removeBall(self):
|
||||
self.ballsLeft -= 1
|
||||
self.specialDisplay.write_ballsToPlay(self.ballsLeft)
|
||||
self.specialDisplay.printBallsToPlay(self.ballsLeft)
|
||||
if(self.ballsLeft == 0):
|
||||
# todo emit endgame Event
|
||||
pass
|
||||
@@ -39,7 +39,7 @@ class PlayerState:
|
||||
self.timer = Timer(self.upperPlayfieldTime, self.stopUpperPlayfieldTimer)
|
||||
|
||||
def stopUpperPlayfieldTimer(self):
|
||||
if(self.timer == None):
|
||||
if not self.timer:
|
||||
return
|
||||
|
||||
self.timer.cancel()
|
||||
@@ -1,5 +1,5 @@
|
||||
from src.networking.Networking import Networking
|
||||
from src.utils.util import normalizeName
|
||||
from networking.Networking import Networking
|
||||
from utils.util import normalizeName
|
||||
|
||||
class Solenoid:
|
||||
def __init__(self, name):
|
||||
@@ -11,4 +11,4 @@ class Solenoid:
|
||||
self.name = normalizeName(solenoidName)
|
||||
|
||||
def trigger(self):
|
||||
Networking.triggerSolenoid(self.name)
|
||||
Networking().triggerSolenoid(self.name)
|
||||
19
__main__.py
Normal file
19
__main__.py
Normal file
@@ -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()
|
||||
BIN
__pycache__/GameState.cpython-38.pyc
Normal file
BIN
__pycache__/GameState.cpython-38.pyc
Normal file
Binary file not shown.
BIN
__pycache__/InputHandler.cpython-38.pyc
Normal file
BIN
__pycache__/InputHandler.cpython-38.pyc
Normal file
Binary file not shown.
BIN
__pycache__/PlayerState.cpython-38.pyc
Normal file
BIN
__pycache__/PlayerState.cpython-38.pyc
Normal file
Binary file not shown.
BIN
__pycache__/Solenoid.cpython-38.pyc
Normal file
BIN
__pycache__/Solenoid.cpython-38.pyc
Normal file
Binary file not shown.
BIN
__pycache__/__main__.cpython-38.pyc
Normal file
BIN
__pycache__/__main__.cpython-38.pyc
Normal file
Binary file not shown.
BIN
__pycache__/config.cpython-38.pyc
Normal file
BIN
__pycache__/config.cpython-38.pyc
Normal file
Binary file not shown.
BIN
__pycache__/test.cpython-38.pyc
Normal file
BIN
__pycache__/test.cpython-38.pyc
Normal file
Binary file not shown.
9
displays/Display.py
Normal file
9
displays/Display.py
Normal file
@@ -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):
|
||||
def __init__(self, name):
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.displays.Display import Display
|
||||
from displays.Display import Display
|
||||
|
||||
class SpecialDisplay(Display):
|
||||
def __init__(self, name):
|
||||
@@ -7,19 +7,19 @@ class SpecialDisplay(Display):
|
||||
self.gameTimeBonus = 0
|
||||
self.ballsToPlay = 0
|
||||
|
||||
def write_score(self):
|
||||
def printScore(self):
|
||||
super.write_score(int(str(self.credits).zfill(2)
|
||||
+ str(self.gameTimeBonus).zfill(2)
|
||||
+ str(self.ballsToPlay).zfill(2)))
|
||||
|
||||
def write_ballsToPlay(self, ballsToPlay):
|
||||
def printBallsToPlay(self, ballsToPlay):
|
||||
self.ballsToPlay = ballsToPlay
|
||||
self.write_score()
|
||||
self.printScore()
|
||||
|
||||
def write_gameTimeBonus(self, gameTimeBonus):
|
||||
def printGameTimeBonus(self, gameTimeBonus):
|
||||
self.gameTimeBonus = gameTimeBonus
|
||||
self.write_score()
|
||||
self.printScore()
|
||||
|
||||
def write_credits(self, credits):
|
||||
def printCredits(self, credits):
|
||||
self.credits = credits
|
||||
self.write_score()
|
||||
self.printScore()
|
||||
BIN
displays/__pycache__/Display.cpython-38.pyc
Normal file
BIN
displays/__pycache__/Display.cpython-38.pyc
Normal file
Binary file not shown.
BIN
displays/__pycache__/PlayerDisplay.cpython-38.pyc
Normal file
BIN
displays/__pycache__/PlayerDisplay.cpython-38.pyc
Normal file
Binary file not shown.
BIN
displays/__pycache__/SpecialDisplay.cpython-38.pyc
Normal file
BIN
displays/__pycache__/SpecialDisplay.cpython-38.pyc
Normal file
Binary file not shown.
@@ -3,4 +3,4 @@ class BonusTimeEvent:
|
||||
self.playerState = playerState
|
||||
|
||||
def trigger(self):
|
||||
self.playerState.addBonusTimeSecond()
|
||||
self.playerState().addBonusTimeSecond()
|
||||
@@ -3,4 +3,4 @@ class EndOfBallEvent:
|
||||
self.playerState = playerState
|
||||
|
||||
def trigger(self):
|
||||
self.playerState.removeBall()
|
||||
self.playerState().removeBall()
|
||||
@@ -5,4 +5,4 @@ class EnterUpperPlayfieldEvent:
|
||||
|
||||
def trigger(self):
|
||||
self.flipper.activate()
|
||||
self.playerState.startUpperPlayfieldTimer()
|
||||
self.playerState().startUpperPlayfieldTimer()
|
||||
6
events/FlapEvent.py
Normal file
6
events/FlapEvent.py
Normal file
@@ -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):
|
||||
self.flipper.deactivate()
|
||||
self.playerState.stopUpperPlayfieldTimer()
|
||||
self.playerState().stopUpperPlayfieldTimer()
|
||||
7
events/LeftFlapEvent.py
Normal file
7
events/LeftFlapEvent.py
Normal file
@@ -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
|
||||
|
||||
def trigger(self, target):
|
||||
self.playerState.addPoints(target.points)
|
||||
self.playerState().addPoints(target.points)
|
||||
7
events/RightFlapEvent.py
Normal file
7
events/RightFlapEvent.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from events.FlapEvent import FlapEvent
|
||||
from solenoids.RightFlapSolenoid import RightFlapSolenoid
|
||||
|
||||
|
||||
class RightFlapEvent(FlapEvent):
|
||||
def __init__(self):
|
||||
super(RightFlapSolenoid())
|
||||
9
events/RightKickerEvent.py
Normal file
9
events/RightKickerEvent.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from solenoids.RightKickerSolenoid import RightKickerSolenoid
|
||||
|
||||
|
||||
class RightKickerEvent:
|
||||
def __init__(self):
|
||||
self.rightKickerSolenoid = RightKickerSolenoid()
|
||||
|
||||
def trigger(self):
|
||||
self.rightKickerSolenoid.trigger()
|
||||
10
events/StartGameEvent.py
Normal file
10
events/StartGameEvent.py
Normal file
@@ -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
|
||||
|
||||
def trigger(self):
|
||||
self.playerState.addUpperPlayfieldTime(1)
|
||||
self.playerState().addUpperPlayfieldTime(1)
|
||||
BIN
events/__pycache__/EndOfBallEvent.cpython-38.pyc
Normal file
BIN
events/__pycache__/EndOfBallEvent.cpython-38.pyc
Normal file
Binary file not shown.
BIN
events/__pycache__/EnterUpperPlayfieldEvent.cpython-38.pyc
Normal file
BIN
events/__pycache__/EnterUpperPlayfieldEvent.cpython-38.pyc
Normal file
Binary file not shown.
BIN
events/__pycache__/FlapEvent.cpython-38.pyc
Normal file
BIN
events/__pycache__/FlapEvent.cpython-38.pyc
Normal file
Binary file not shown.
BIN
events/__pycache__/LeftFlapEvent.cpython-38.pyc
Normal file
BIN
events/__pycache__/LeftFlapEvent.cpython-38.pyc
Normal file
Binary file not shown.
BIN
events/__pycache__/PointEvent.cpython-38.pyc
Normal file
BIN
events/__pycache__/PointEvent.cpython-38.pyc
Normal file
Binary file not shown.
BIN
events/__pycache__/RightFlapEvent.cpython-38.pyc
Normal file
BIN
events/__pycache__/RightFlapEvent.cpython-38.pyc
Normal file
Binary file not shown.
BIN
events/__pycache__/RightKickerEvent.cpython-38.pyc
Normal file
BIN
events/__pycache__/RightKickerEvent.cpython-38.pyc
Normal file
Binary file not shown.
BIN
events/__pycache__/StartGameEvent.cpython-38.pyc
Normal file
BIN
events/__pycache__/StartGameEvent.cpython-38.pyc
Normal file
Binary file not shown.
14
factories/DisplayFactory.py
Normal file
14
factories/DisplayFactory.py
Normal file
@@ -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)
|
||||
53
factories/EventFactory.py
Normal file
53
factories/EventFactory.py
Normal file
@@ -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)
|
||||
47
factories/GameFactory.py
Normal file
47
factories/GameFactory.py
Normal file
@@ -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
|
||||
|
||||
7
factories/NetworkFactory.py
Normal file
7
factories/NetworkFactory.py
Normal file
@@ -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)
|
||||
9
factories/PlayerStateFactory.py
Normal file
9
factories/PlayerStateFactory.py
Normal file
@@ -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)
|
||||
31
factories/TargetFactory.py
Normal file
31
factories/TargetFactory.py
Normal file
@@ -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
|
||||
BIN
factories/__pycache__/DisplayFactory.cpython-38.pyc
Normal file
BIN
factories/__pycache__/DisplayFactory.cpython-38.pyc
Normal file
Binary file not shown.
BIN
factories/__pycache__/EventFactory.cpython-38.pyc
Normal file
BIN
factories/__pycache__/EventFactory.cpython-38.pyc
Normal file
Binary file not shown.
BIN
factories/__pycache__/GameFactory.cpython-38.pyc
Normal file
BIN
factories/__pycache__/GameFactory.cpython-38.pyc
Normal file
Binary file not shown.
BIN
factories/__pycache__/PlayerStateFactory.cpython-38.pyc
Normal file
BIN
factories/__pycache__/PlayerStateFactory.cpython-38.pyc
Normal file
Binary file not shown.
BIN
factories/__pycache__/TargetFactory.cpython-38.pyc
Normal file
BIN
factories/__pycache__/TargetFactory.cpython-38.pyc
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
import requests_unixsocket as req
|
||||
import socket
|
||||
from src.utils.Singleton import Singleton
|
||||
from utils.Singleton import Singleton
|
||||
|
||||
|
||||
class Networking(metaclass=Singleton):
|
||||
@@ -47,7 +47,7 @@ class Networking(metaclass=Singleton):
|
||||
def writeDisplayScore(self, display, score):
|
||||
self.get("/displays/" + display + "/write_score/" + str(score))
|
||||
|
||||
def getInputEvent(self):
|
||||
async def getInputEvent(self):
|
||||
header = list()
|
||||
while b'\x02' not in header:
|
||||
byte = self.input_socket.recv(1)
|
||||
BIN
networking/__pycache__/Networking.cpython-38.pyc
Normal file
BIN
networking/__pycache__/Networking.cpython-38.pyc
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class BottomLeftBankSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class BottomRightBankSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class BottomRightPopSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class CoinMechanismCoilSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class KnockerSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class LeftFlapSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class OutHoleSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class RightFlapSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class RightKickerSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class TopCentralBankSolenoid(Solenoid):
|
||||
pass
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.Solenoid import Solenoid
|
||||
from Solenoid import Solenoid
|
||||
|
||||
class TopLeftPopSolenoid(Solenoid):
|
||||
pass
|
||||
BIN
solenoids/__pycache__/LeftFlapSolenoid.cpython-38.pyc
Normal file
BIN
solenoids/__pycache__/LeftFlapSolenoid.cpython-38.pyc
Normal file
Binary file not shown.
BIN
solenoids/__pycache__/OutHoleSolenoid.cpython-38.pyc
Normal file
BIN
solenoids/__pycache__/OutHoleSolenoid.cpython-38.pyc
Normal file
Binary file not shown.
BIN
solenoids/__pycache__/RightFlapSolenoid.cpython-38.pyc
Normal file
BIN
solenoids/__pycache__/RightFlapSolenoid.cpython-38.pyc
Normal file
Binary file not shown.
BIN
solenoids/__pycache__/RightKickerSolenoid.cpython-38.pyc
Normal file
BIN
solenoids/__pycache__/RightKickerSolenoid.cpython-38.pyc
Normal file
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
src/game.py
46
src/game.py
@@ -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):
|
||||
def __init__(self, points, name, targets):
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.targets.Target import Target
|
||||
from targets.Target import Target
|
||||
|
||||
class BankTarget(Target):
|
||||
def __init__(self, points):
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.targets.Target import Target
|
||||
from targets.Target import Target
|
||||
|
||||
class ReboundContactTarget(Target):
|
||||
def __init__(self):
|
||||
BIN
targets/__pycache__/Bank.cpython-38.pyc
Normal file
BIN
targets/__pycache__/Bank.cpython-38.pyc
Normal file
Binary file not shown.
BIN
targets/__pycache__/BankTarget.cpython-38.pyc
Normal file
BIN
targets/__pycache__/BankTarget.cpython-38.pyc
Normal file
Binary file not shown.
BIN
targets/__pycache__/ReboundContactTarget.cpython-38.pyc
Normal file
BIN
targets/__pycache__/ReboundContactTarget.cpython-38.pyc
Normal file
Binary file not shown.
BIN
targets/__pycache__/Target.cpython-38.pyc
Normal file
BIN
targets/__pycache__/Target.cpython-38.pyc
Normal file
Binary file not shown.
BIN
targets/__pycache__/__init__.cpython-38.pyc
Normal file
BIN
targets/__pycache__/__init__.cpython-38.pyc
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
from src.targets.Target import Target
|
||||
from targets.Target import Target
|
||||
|
||||
class LeftInlaneTarget(Target):
|
||||
def __init__(self):
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.targets.Target import Target
|
||||
from targets.Target import Target
|
||||
|
||||
class LeftOutlaneTarget(Target):
|
||||
def __init__(self):
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.targets.Target import Target
|
||||
from targets.Target import Target
|
||||
|
||||
|
||||
class RightInlaneTarget(Target):
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.targets.Target import Target
|
||||
from targets.Target import 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