From f6c1fcc1f7306ee356f2f3af2f1626d29bf3e39f Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Tue, 30 Aug 2022 18:09:42 +0200 Subject: [PATCH] bla --- events/StartGameEvent.py | 1 + factories/DisplayFactory.py | 10 +++++++++- factories/GameFactory.py | 3 ++- factories/PlayerStateFactory.py | 7 +++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/events/StartGameEvent.py b/events/StartGameEvent.py index 8dbf322..7886827 100644 --- a/events/StartGameEvent.py +++ b/events/StartGameEvent.py @@ -22,6 +22,7 @@ class StartGameEvent(Event): def restart_timer(self): if self.timer is not None: self.timer.cancel() + self.timer = Timer(interval=config.PLAYER_CHOOSE_INTERVAL, function=self.player_choose_ended) self.timer.start() diff --git a/factories/DisplayFactory.py b/factories/DisplayFactory.py index ce3214b..b8f9090 100644 --- a/factories/DisplayFactory.py +++ b/factories/DisplayFactory.py @@ -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) diff --git a/factories/GameFactory.py b/factories/GameFactory.py index 6b26be7..4839c12 100644 --- a/factories/GameFactory.py +++ b/factories/GameFactory.py @@ -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): diff --git a/factories/PlayerStateFactory.py b/factories/PlayerStateFactory.py index 88695e7..c440be2 100644 --- a/factories/PlayerStateFactory.py +++ b/factories/PlayerStateFactory.py @@ -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()