changeset 144:a9b800b4175e

Add define for henhouses & egg laying.
author Neil Muller <drnlmuller@gmail.com>
date Thu, 03 Sep 2009 14:59:13 +0000
parents f174ef6b26ba
children 490ede177f50
files gamelib/buildings.py gamelib/gameboard.py
diffstat 2 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/buildings.py	Thu Sep 03 10:56:38 2009 +0000
+++ b/gamelib/buildings.py	Thu Sep 03 14:59:13 2009 +0000
@@ -200,6 +200,9 @@
     """Return true if obj is a build class."""
     return getattr(obj, "IS_BUILDING", False) and hasattr(obj, "NAME")
 
+# Building hens can lay eggs in
+HENHOUSES = [HenHouse.NAME, DoubleStoryHenHouse.NAME]
+
 BUILDINGS = []
 for name in dir():
     obj = eval(name)
--- a/gamelib/gameboard.py	Thu Sep 03 10:56:38 2009 +0000
+++ b/gamelib/gameboard.py	Thu Sep 03 14:59:13 2009 +0000
@@ -447,7 +447,7 @@
     def lay_eggs(self):
         self.eggs = 0
         for building in self.buildings:
-            if building.NAME in [buildings.HenHouse.NAME]:
+            if building.NAME in buildings.HENHOUSES:
                 for chicken in building.occupants():
                     chicken.lay()
                     if chicken.egg:
@@ -456,7 +456,7 @@
 
     def hatch_eggs(self):
         for building in self.buildings:
-            if building.NAME in [buildings.HenHouse.NAME]:
+            if building.NAME in buildings.HENHOUSES:
                 for chicken in building.occupants():
                     new_chick = chicken.hatch()
                     if new_chick:
@@ -488,9 +488,8 @@
         if chick.abode:
             chick.abode.clear_occupant()
         self.toolbar.update_chicken_counter(len(self.chickens))
-        if chick in self.tv.sprites:
-            if chick.outside():
-                self.tv.sprites.remove(chick)
+        if chick in self.tv.sprites and chick.outside():
+            self.tv.sprites.remove(chick)
 
     def remove_building(self, building):
         if building in self.buildings: