From: Simon Cross Date: Sat, 10 Sep 2016 14:47:44 +0000 (+0200) Subject: Add battery pack manager. X-Git-Tag: tabakrolletjie-v1.0.0~93 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=30c82e09458a64a2f30d3629b56f28a235d45296;p=tabakrolletjie.git Add battery pack manager. --- diff --git a/tabakrolletjie/battery.py b/tabakrolletjie/battery.py new file mode 100644 index 0000000..c543698 --- /dev/null +++ b/tabakrolletjie/battery.py @@ -0,0 +1,36 @@ +""" Keep 'em charged and they'll never let you down. """ + + +class BatteryManager(object): + """ Manages a battery. """ + + def __init__(self, gamestate): + self._state = gamestate.station["battery"] + + @property + def current(self): + return self._state["current"] + + @current.setter + def current(self, value): + self._state["current"] = min(max(0, value), self.max) + + @property + def max(self): + return self._state["max"] + + @max.setter + def max(self, value): + self._state["max"] = max(0, value) + + @property + def recharge(self): + return self._state["recharge"] + + @recharge.setter + def recharge(self, value): + self._state["recharge"] = max(0, value) + + def apply_recharge(self): + self.current += self.recharge + print self.current