refactor timer
This commit is contained in:
@@ -31,4 +31,4 @@ MAX_NETWORK_RETRIES = 10
|
|||||||
NETWORK_SLEEP_TIME_SECONDS = 0.1
|
NETWORK_SLEEP_TIME_SECONDS = 0.1
|
||||||
BANK_SLEEP_TIME = 0.1
|
BANK_SLEEP_TIME = 0.1
|
||||||
BONUS_SLEEP_TIME = 0.1
|
BONUS_SLEEP_TIME = 0.1
|
||||||
PLAYER_CHOOSE_INTERVAL = 3
|
PLAYER_CHOOSE_INTERVAL = 1
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import config
|
|||||||
|
|
||||||
from lamps.LampGroup import PLAYER_LAMPS
|
from lamps.LampGroup import PLAYER_LAMPS
|
||||||
|
|
||||||
|
|
||||||
class StartGameEvent(Event):
|
class StartGameEvent(Event):
|
||||||
isPlayerChoosing = True
|
|
||||||
playerCount = 1
|
playerCount = 1
|
||||||
timer = None
|
timer = None
|
||||||
|
|
||||||
@@ -19,17 +19,19 @@ class StartGameEvent(Event):
|
|||||||
self.outHoleSolenoid = OutHoleSolenoid()
|
self.outHoleSolenoid = OutHoleSolenoid()
|
||||||
super().__init__("Start Game Event")
|
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):
|
def trigger(self, target):
|
||||||
if self.gameState.isPlaying:
|
if self.gameState.isPlaying:
|
||||||
return
|
return
|
||||||
|
|
||||||
super().trigger(target)
|
super().trigger(target)
|
||||||
|
|
||||||
if not self.isPlayerChoosing:
|
self.restart_timer()
|
||||||
self.isPlayerChoosing = True
|
|
||||||
self.timer = Timer(interval=config.PLAYER_CHOOSE_INTERVAL, function=self.player_choose_ended)
|
|
||||||
self.timer.start()
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.playerCount == config.MAX_PLAYERS:
|
if self.playerCount == config.MAX_PLAYERS:
|
||||||
PLAYER_LAMPS.deactivate()
|
PLAYER_LAMPS.deactivate()
|
||||||
|
|||||||
Reference in New Issue
Block a user