Color roaches according to their abilities.
authorSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 21:39:33 +0000 (23:39 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 21:39:33 +0000 (23:39 +0200)
koperkapel/roaches.py
koperkapel/world.py

index 904b8c7dfc9bdf927018cb200372080ce97ca635..20220c4c6da52165651910e691ad354d62c83dde 100644 (file)
@@ -10,6 +10,7 @@ ROACH_COLORS = {
     "blue": (0, 0, 255, 255),
     "green": (0, 255, 0, 255),
     "purple": (255, 0, 255, 255),
+    "brown": (170, 68, 0, 255),
 }
 
 
@@ -37,8 +38,14 @@ class RoachFactory:
         self.suffix = suffix
         self.frames = 4
 
-    def roach_color(self, roach_data):
-        return random.choice(list(ROACH_COLORS.values()))
+    def roach_color(self, roach):
+        if roach.smart:
+            return ROACH_COLORS["blue"]
+        elif roach.fast:
+            return ROACH_COLORS["green"]
+        elif roach.strong:
+            return ROACH_COLORS["purple"]
+        return ROACH_COLORS["brown"]
 
     def assemble_frame(self, i, color, roach_data):
         roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
index f06d3bcbca1f4063e91dd9f300191c3f1f1639e1..f03bffa1a88e7945e429dc9319c7228096e1dc54 100644 (file)
@@ -20,9 +20,10 @@ class World:
     def _build_initial_state(self):
         state = {}
         state["roaches"] = [
-            self._build_roach("roachel", intelligence=3),
-            self._build_roach("roeginald", strength=3),
-            self._build_roach("roichard", quickness=3),
+            self._build_roach("roachel", smart=True),
+            self._build_roach("roeginald", strong=True),
+            self._build_roach("roichard", fast=True),
+            self._build_roach("roupert"),
         ]
         state["vehicles"] = {
             "current": "walking",
@@ -33,18 +34,13 @@ class World:
         }
         return state
 
-    def _build_roach(self, name, **kw):
-        attributes = {
-            "intelligence": 1,
-            "strength": 1,
-            "quickness": 1,
-            "health": 5,
-        }
-        attributes.update(kw)
-        return {
+    def _build_roach(self, name, health=5, **kw):
+        roach = {
             "name": name,
-            "attributes": attributes,
+            "health": health,
         }
+        roach.update(kw)
+        return roach
 
     def _apply_set(self, updates):
         for name, value in updates.items():
@@ -116,7 +112,9 @@ class WorldDictProxy(WorldBaseProxy):
         self._top._record_change("%s%s" % (self._prefix, name), value)
 
     def __getattr__(self, name):
-        return _maybe_subproxy(self, name, self._state[name])
+        # return None for attributes that don't exist
+        value = self._state.get(name)
+        return _maybe_subproxy(self, name, value)
 
 
 class WorldListProxy(WorldBaseProxy):