refactor timer
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user