fix player lamps

This commit is contained in:
Jonas Zeunert
2022-06-07 00:28:17 +02:00
parent e0ccc25680
commit 622c067a7a
2 changed files with 19 additions and 8 deletions

View File

@@ -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()

View File

@@ -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"),