Files
flippr-game/events/EndBallEvent.py
Jonas Zeunert 0ef881bb91 bubb
2022-08-31 15:07:44 +02:00

48 lines
1.5 KiB
Python

import config
from Event import Event
from events.StartBallEvent import StartBallEvent
from solenoids.MainFlipper import MainFlipper
from solenoids.TopFlipper import TopFlipper
from solenoids.OutHoleSolenoid import OutHoleSolenoid
from time import sleep
from config import BONUS_SLEEP_TIME
from lamps.LampGroup import BONUS_LAMPS
class EndBallEvent(Event):
def __init__(self, gameState):
self.gameState = gameState
super().__init__("End Of Ball Event")
def trigger(self, target):
super().trigger(target)
TopFlipper().deactivate()
MainFlipper().deactivate()
if self.gameState.currentPlayer.replayBall or not self.gameState.currentPlayer.hasBallScored:
OutHoleSolenoid().trigger()
return
self.gameState.isPlaying = False
self.gameState.currentPlayer.removeBall()
self.scorePoints()
self.gameState.currentPlayer.deactivate()
if self.gameState.currentPlayer.ballsLeft == 0 and self.gameState.currentPlayer.id == config.MAX_PLAYERS - 1:
self.gameState.endGame()
return
self.gameState.nextPlayer()
def scorePoints(self):
currentPlayer = self.gameState.currentPlayer
for i in range(currentPlayer.bonus):
bonus = self.gameState.currentPlayer.bonusMultiplier * 1000
self.gameState.currentPlayer.addPoints(bonus)
BONUS_LAMPS.deactivateCurrent()
sleep(BONUS_SLEEP_TIME)