refactor timer

This commit is contained in:
Jonas Zeunert
2022-08-30 17:13:53 +02:00
parent a093ec34ca
commit 808c9bbd28
2 changed files with 9 additions and 7 deletions

View File

@@ -8,8 +8,8 @@ import config
from lamps.LampGroup import PLAYER_LAMPS
class StartGameEvent(Event):
isPlayerChoosing = True
playerCount = 1
timer = None
@@ -19,17 +19,19 @@ class StartGameEvent(Event):
self.outHoleSolenoid = OutHoleSolenoid()
super().__init__("Start Game 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()
def trigger(self, target):
if self.gameState.isPlaying:
return
super().trigger(target)
if not self.isPlayerChoosing:
self.isPlayerChoosing = True
self.timer = Timer(interval=config.PLAYER_CHOOSE_INTERVAL, function=self.player_choose_ended)
self.timer.start()
return
self.restart_timer()
if self.playerCount == config.MAX_PLAYERS:
PLAYER_LAMPS.deactivate()