fix player lamps
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user