From 30c82e09458a64a2f30d3629b56f28a235d45296 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 10 Sep 2016 16:47:44 +0200 Subject: [PATCH] Add battery pack manager. --- tabakrolletjie/battery.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tabakrolletjie/battery.py 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 -- 2.34.1