Files
flippr-game/events/EndBallEvent.py
Jonas Zeunert 4da7a3110d Add replay ball
2022-08-31 14:50:11 +02:00

46 lines
1.4 KiB
Python

import config
from Event import Event
from events.StartBallEvent import StartBallEvent
from solenoids.MainFlipper import MainFlipper
from solenoids.TopFlipper import TopFlipper
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:
StartBallEvent().trigger(None)
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)