62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
from Event import Event
|
|
from events.StartBallEvent import StartBallEvent
|
|
from solenoids.OutHoleSolenoid import OutHoleSolenoid
|
|
from solenoids.MainFlipper import MainFlipper
|
|
|
|
from threading import Timer
|
|
import config
|
|
|
|
from lamps.LampGroup import PLAYER_LAMPS
|
|
|
|
|
|
class StartGameEvent(Event):
|
|
playerCount = 1
|
|
timer = None
|
|
|
|
def __init__(self, gameState):
|
|
self.gameState = gameState
|
|
self.flipper = MainFlipper()
|
|
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.isStarted:
|
|
return
|
|
|
|
if not self.gameState.isIdle:
|
|
return
|
|
|
|
super().trigger(target)
|
|
|
|
self.gameState.stopIdleLoop()
|
|
|
|
if self.timer is None:
|
|
PLAYER_LAMPS.deactivate()
|
|
PLAYER_LAMPS.activateNext()
|
|
self.restart_timer()
|
|
return
|
|
|
|
self.restart_timer()
|
|
|
|
if self.playerCount == config.MAX_PLAYERS:
|
|
PLAYER_LAMPS.deactivate()
|
|
PLAYER_LAMPS.activateNext()
|
|
self.playerCount = 1
|
|
return
|
|
|
|
PLAYER_LAMPS.activate_one(self.playerCount)
|
|
self.playerCount += 1
|
|
|
|
def player_choose_ended(self):
|
|
self.timer = None
|
|
PLAYER_LAMPS.deactivate()
|
|
self.gameState.startGame(self.playerCount)
|
|
StartBallEvent().trigger(None)
|