This commit is contained in:
Jonas Zeunert
2022-08-30 18:09:42 +02:00
parent 808c9bbd28
commit f6c1fcc1f7
4 changed files with 15 additions and 6 deletions

View File

@@ -1,10 +1,18 @@
from displays.PlayerDisplay import PlayerDisplay
from displays.SpecialDisplay import SpecialDisplay
import config
class DisplayFactory:
def __init__(self, displayNames):
self.displayNames = displayNames
def createDisplays(self):
displays = [None] * config.MAX_PLAYERS
for displayName in self.displayNames:
if "Player" in displayName:
id = displayName.replace("Player", "")
displays[id] = PlayerDisplay(displayName)
return displays
def createSpecialDisplay(self):
name = next(displayName['name'] for displayName in self.displayNames if "Special" in displayName['name'])
return SpecialDisplay(name)

View File

@@ -15,6 +15,7 @@ class GameFactory:
def __init__(self):
displayNames = networking.getDisplays()['displays']
self.displayFactory = DisplayFactory(displayNames)
self.displays = self.displayFactory.createDisplays()
self.specialDisplay = self.displayFactory.createSpecialDisplay()
self.playerCount = len(displayNames)
@@ -22,7 +23,7 @@ class GameFactory:
self.targets = TargetFactory.createAllTargets()
banks = [self.targets['Left Bank'], self.targets['Right Bank'], self.targets['Top Bank']]
self.playerStateFactory = PlayerStateFactory(self.specialDisplay, banks, self.displayFactory)
self.playerStateFactory = PlayerStateFactory(self.specialDisplay, banks, self.displays)
def createGame(self):

View File

@@ -3,14 +3,13 @@ from PlayerState import PlayerState
from displays.DummyDisplay import DummyDisplay
class PlayerStateFactory:
def __init__(self, specialDisplay, banks, displayFactory):
def __init__(self, specialDisplay, banks, displays):
self.specialDisplay = specialDisplay
self.banks = banks
self.displayFactory = displayFactory
self.displays = displays
def createPlayerState(self, id):
display = self.displayFactory.createPlayerDisplay(id)
return PlayerState(display, self.specialDisplay, id, BALLS_PER_GAME, self.banks)
return PlayerState(self.displays[id], self.specialDisplay, id, BALLS_PER_GAME, self.banks)
def createDummyPlayerState(self):
display = DummyDisplay()