diff gamelib/buildings.py @ 108:437cbd856a03

Add occupants and abodes. Allowing moving chickens around.
author Simon Cross <hodgestar@gmail.com>
date Wed, 02 Sep 2009 18:42:00 +0000
parents 7e9c8ad06d32
children 48019afde338
line wrap: on
line diff
--- a/gamelib/buildings.py	Wed Sep 02 18:26:15 2009 +0000
+++ b/gamelib/buildings.py	Wed Sep 02 18:42:00 2009 +0000
@@ -19,6 +19,7 @@
         self.tile_no = self.TILE_NO
         self._buy_price = self.BUY_PRICE
         self._sell_price = self.SELL_PRICE
+        self._occupants = set()
 
         # Create the building somewhere far off screen
         Sprite.__init__(self, self.day_image, (-1000, -1000))
@@ -84,6 +85,20 @@
         else:
             self.setimage(self.night_image)
 
+    def occupants(self):
+        """Return list of buildings occupants."""
+        return list(self._occupants)
+
+    def add_occupant(self, occupant):
+        if occupant.abode is not None:
+            occupant.abode.remove_occupant(occupant)
+        occupant.abode = self
+        self._occupants.add(occupant)
+
+    def remove_occupant(self, occupant):
+        if occupant in self._occupants:
+            self._occupants.remove(occupant)
+            occupant.abode = None
 
 class HenHouse(Building):
     """A HenHouse."""