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)) logging.info("Set active player to player " + str(player.id))
self._currentPlayer = self.dummyPlayer self._currentPlayer = self.dummyPlayer
PLAYER_LAMPS.deactivateCurrent() PLAYER_LAMPS.cycle()
PLAYER_LAMPS.activateNext()
player.activate() player.activate()

View File

@@ -1,10 +1,12 @@
from lamps.Lamp import Lamp from lamps.Lamp import Lamp
from itertools import cycle
class LampGroup: class LampGroup:
def __init__(self, lamps): def __init__(self, lamps):
self.lamps = lamps self.lamps = lamps
self.currentLamp = 0 self.currentLampPtr = 0
self.lamp_cycle = cycle(lamps)
self.currentLamp = None
self.deactivate() self.deactivate()
def activate(self): def activate(self):
@@ -12,22 +14,32 @@ class LampGroup:
lamp.activate() lamp.activate()
def deactivate(self): def deactivate(self):
self.currentLamp = 0 self.currentLampPtr = 0
for lamp in self.lamps: for lamp in self.lamps:
lamp.deactivate() lamp.deactivate()
def activateNext(self): 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 return
self.currentLamp += 1 self.currentLampPtr += 1
def deactivateCurrent(self): def deactivateCurrent(self):
self.lamps[self.currentLamp].deactivate() 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([ PLAYER_LAMPS = LampGroup([
Lamp("Can Play 1"), Lamp("Can Play 1"),
Lamp("Can Play 2"), Lamp("Can Play 2"),