From 5fb8bb54f02c997941d6251eb0f243394517be2c Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Wed, 31 Aug 2022 17:28:24 +0200 Subject: [PATCH] kjdsa --- GameState.py | 20 ++++++++++++-------- lamps/LampGroup.py | 6 ++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/GameState.py b/GameState.py index 5ee1f42..9593f8d 100644 --- a/GameState.py +++ b/GameState.py @@ -11,7 +11,7 @@ class GameState: credits = config.BALLS_PER_GAME isPlaying = False isStarted = False - isIdle = True + isIdle = asyncio.Event() def __init__(self, playerStateFactory, highscore, specialDisplay, currentPlayerID = 0): CREDIT.activate() @@ -48,7 +48,7 @@ class GameState: pass def stopIdleLoop(self): - self.isIdle = False + self.isIdle.set() pass async def idleLoop(self): @@ -56,12 +56,16 @@ class GameState: 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.1) + #for lamps in all_cabinet_lamps: + #for _ in lamps.lamps: + #lamps.cycle() + #if not self.isIdle: + # return + #time.sleep(0.1) + random_group = random.choice(all_cabinet_lamps) + random_group.toggleRandom(0.2) + if self.isIdle.is_set(): + return def createPlayers(self, playerCount): players = [] diff --git a/lamps/LampGroup.py b/lamps/LampGroup.py index c03433e..f8fee97 100644 --- a/lamps/LampGroup.py +++ b/lamps/LampGroup.py @@ -1,5 +1,6 @@ from lamps.Lamp import Lamp from itertools import cycle +import random import time class LampGroup: @@ -39,6 +40,11 @@ class LampGroup: self.currentLampPtr -= 1 + def toggleRandom(self, sleepTime): + random_lamp = random.choice(self.lamps) + random_lamp.activate() + time.sleep(sleepTime) + random_lamp.deactivate() def cycle(self): if self.currentLamp: self.currentLamp.deactivate()