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

@@ -22,6 +22,7 @@ class StartGameEvent(Event):
def restart_timer(self): def restart_timer(self):
if self.timer is not None: if self.timer is not None:
self.timer.cancel() self.timer.cancel()
self.timer = Timer(interval=config.PLAYER_CHOOSE_INTERVAL, function=self.player_choose_ended) self.timer = Timer(interval=config.PLAYER_CHOOSE_INTERVAL, function=self.player_choose_ended)
self.timer.start() self.timer.start()

View File

@@ -1,10 +1,18 @@
from displays.PlayerDisplay import PlayerDisplay from displays.PlayerDisplay import PlayerDisplay
from displays.SpecialDisplay import SpecialDisplay from displays.SpecialDisplay import SpecialDisplay
import config
class DisplayFactory: class DisplayFactory:
def __init__(self, displayNames): def __init__(self, displayNames):
self.displayNames = 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): def createSpecialDisplay(self):
name = next(displayName['name'] for displayName in self.displayNames if "Special" in displayName['name']) name = next(displayName['name'] for displayName in self.displayNames if "Special" in displayName['name'])
return SpecialDisplay(name) return SpecialDisplay(name)

View File

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

View File

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