From 622c067a7af01e61ef83baf413600d82f903f241 Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Tue, 7 Jun 2022 00:28:17 +0200 Subject: [PATCH] fix player lamps --- GameState.py | 3 +-- lamps/LampGroup.py | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/GameState.py b/GameState.py index 7e90d9c..f82e4a0 100644 --- a/GameState.py +++ b/GameState.py @@ -30,8 +30,7 @@ class GameState: logging.info("Set active player to player " + str(player.id)) self._currentPlayer = self.dummyPlayer - PLAYER_LAMPS.deactivateCurrent() - PLAYER_LAMPS.activateNext() + PLAYER_LAMPS.cycle() player.activate() diff --git a/lamps/LampGroup.py b/lamps/LampGroup.py index 3221027..3cb01ca 100644 --- a/lamps/LampGroup.py +++ b/lamps/LampGroup.py @@ -1,10 +1,12 @@ from lamps.Lamp import Lamp - +from itertools import cycle class LampGroup: def __init__(self, lamps): self.lamps = lamps - self.currentLamp = 0 + self.currentLampPtr = 0 + self.lamp_cycle = cycle(lamps) + self.currentLamp = None self.deactivate() def activate(self): @@ -12,22 +14,32 @@ class LampGroup: lamp.activate() def deactivate(self): - self.currentLamp = 0 + self.currentLampPtr = 0 for lamp in self.lamps: lamp.deactivate() def activateNext(self): - self.lamps[self.currentLamp].activate() + self.lamps[self.currentLampPtr].activate() - if self.currentLamp == len(self.lamps) - 1: + if self.currentLampPtr == len(self.lamps) - 1: return - self.currentLamp += 1 + self.currentLampPtr += 1 def deactivateCurrent(self): self.lamps[self.currentLamp].deactivate() + if self.currentLampPtr == 0: + return + + self.currentLampPtr -= 1 + + def cycle(self): + self.currentLamp.deactivate() + self.currentLamp = next(self.lamp_cycle) + self.currentLamp.activate() + PLAYER_LAMPS = LampGroup([ Lamp("Can Play 1"), Lamp("Can Play 2"),