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