diff --git a/GameState.py b/GameState.py index 9da0c65..57c08c0 100644 --- a/GameState.py +++ b/GameState.py @@ -1,16 +1,17 @@ import logging import config -from lamps.LampGroup import PLAYER_LAMPS from lamps.Lamp import CREDIT from itertools import cycle -from time import sleep +from lamps.LampGroup import * +import asyncio class GameState: players = None credits = config.BALLS_PER_GAME isPlaying = False isStarted = False + isIdle = True def __init__(self, playerStateFactory, highscore, specialDisplay, currentPlayerID = 0): CREDIT.activate() @@ -22,6 +23,7 @@ class GameState: self.highscore = highscore self.specialDisplay = specialDisplay self.specialDisplay.printCredits(self.credits) + self.startIdleLoop() def nextPlayer(self): self.currentPlayer = next(self.players) @@ -42,14 +44,24 @@ class GameState: logging.info("Game ended") def startIdleLoop(self): + asyncio.run(self.idleLoop()) pass def stopIdleLoop(self): + self.isIdle = False pass - def idleLoop(self): - - pass + async def idleLoop(self): + all_cabinet_lamps = [BONUS_LAMPS, BONUS_MULTIPLIER_LAMPS, CHAMP_LAMPS, + UPPER_PLAYFIELD_TIME_LAMPS, TUNNEL_NUMBER_LAMPS, + TUNNEL_LAMPS, TUNNEL_SCORE_LAMPS] + while True: + for lamps in all_cabinet_lamps: + for _ in lamps.lamps: + lamps.cycle() + if not self.isIdle: + return + time.sleep(0.5) def createPlayers(self, playerCount): players = [] @@ -77,6 +89,4 @@ class GameState: for player in self.players: if player.hasHighscore: with open(config.HIGHSCORE_FILE, "w+") as file: - file.seek(0) - file.truncate() file.write(player.score) \ No newline at end of file diff --git a/PlayerState.py b/PlayerState.py index 34a8933..fcc8e15 100644 --- a/PlayerState.py +++ b/PlayerState.py @@ -85,6 +85,7 @@ class PlayerState: self.printSpecial() def activate(self): + self.isActive = False self.resetBall() PLAYER_LAMPS.deactivate() PLAYER_LAMPS.activate_one(self.id) @@ -280,6 +281,7 @@ class PlayerState: def advanceBonusMultiplier(self): if not self.isActive: return + try: self.bonusMultiplier = next(self.bonusMultiplierIter) BONUS_MULTIPLIER_LAMPS.activateNext() @@ -292,6 +294,7 @@ class PlayerState: if self.ballsLeft == 0 and self.bonusTime != 0: self.replayBall = True + SHOOT_AGAIN.activate() if self.replayBallTimer != None: self.replayBallTimer.cancel() self.replayBallTimer = Timer(interval=1, function=self.updateReplayBall) @@ -314,6 +317,7 @@ class PlayerState: self.replayBall = False self.replayBallTimer = None + SHOOT_AGAIN.deactivate() MainFlipper().deactivate() def addPoints(self, points): diff --git a/__main__.py b/__main__.py index 8a2dc07..41b076b 100644 --- a/__main__.py +++ b/__main__.py @@ -11,7 +11,7 @@ import logging def main(): args = parseCommandLine() - logging.basicConfig(filename='log.txt', level=config.LOG_LEVEL) + logging.basicConfig(filename=config.LOG_FILE, level=config.LOG_LEVEL) game = createGame(args) asyncio.run(game.run()) diff --git a/config.py b/config.py index 510d473..441a862 100644 --- a/config.py +++ b/config.py @@ -27,6 +27,7 @@ RED_SPECIAL_TIMES = 1 ORANGE_SPECIAL = SpecialEvent.points ORANGE_SPECIAL_BANK = ORANGE_SPECIAL_BANK_OPTIONS["BOTH"] ## Tech config +LOG_FILE="flippr-game.log" LOG_LEVEL=logging.DEBUG WAIT_TIME_TO_RESET_SECONDS = 1 MAX_NETWORK_RETRIES = 10 diff --git a/lamps/LampGroup.py b/lamps/LampGroup.py index 3a3e10c..c03433e 100644 --- a/lamps/LampGroup.py +++ b/lamps/LampGroup.py @@ -1,5 +1,6 @@ from lamps.Lamp import Lamp from itertools import cycle +import time class LampGroup: def __init__(self, lamps): @@ -44,6 +45,9 @@ class LampGroup: self.currentLamp = next(self.lamp_cycle) self.currentLamp.activate() + + + PLAYER_LAMPS = LampGroup([ Lamp("Can Play 1"), Lamp("Can Play 2"),