comparison 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
comparison
equal deleted inserted replaced
107:672cc5598e77 108:437cbd856a03
17 self.pos = pos 17 self.pos = pos
18 self.size = self.SIZE 18 self.size = self.SIZE
19 self.tile_no = self.TILE_NO 19 self.tile_no = self.TILE_NO
20 self._buy_price = self.BUY_PRICE 20 self._buy_price = self.BUY_PRICE
21 self._sell_price = self.SELL_PRICE 21 self._sell_price = self.SELL_PRICE
22 self._occupants = set()
22 23
23 # Create the building somewhere far off screen 24 # Create the building somewhere far off screen
24 Sprite.__init__(self, self.day_image, (-1000, -1000)) 25 Sprite.__init__(self, self.day_image, (-1000, -1000))
25 26
26 def tile_positions(self): 27 def tile_positions(self):
82 if sun_on: 83 if sun_on:
83 self.setimage(self.day_image) 84 self.setimage(self.day_image)
84 else: 85 else:
85 self.setimage(self.night_image) 86 self.setimage(self.night_image)
86 87
88 def occupants(self):
89 """Return list of buildings occupants."""
90 return list(self._occupants)
91
92 def add_occupant(self, occupant):
93 if occupant.abode is not None:
94 occupant.abode.remove_occupant(occupant)
95 occupant.abode = self
96 self._occupants.add(occupant)
97
98 def remove_occupant(self, occupant):
99 if occupant in self._occupants:
100 self._occupants.remove(occupant)
101 occupant.abode = None
87 102
88 class HenHouse(Building): 103 class HenHouse(Building):
89 """A HenHouse.""" 104 """A HenHouse."""
90 105
91 TILE_NO = tiles.REVERSE_TILE_MAP['henhouse'] 106 TILE_NO = tiles.REVERSE_TILE_MAP['henhouse']