Mercurial > rinkhals
comparison gamelib/gameboard.py @ 115:2b2007e231da
Start of dialog for placing chickens in buildings. Remove chicken in hen house bug by not allowing chickens in hen houses.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Wed, 02 Sep 2009 19:40:28 +0000 |
parents | 48019afde338 |
children | d539ef5a3333 |
comparison
equal
deleted
inserted
replaced
114:4c2fbab20abe | 115:2b2007e231da |
---|---|
228 self.animal_to_place = chicken | 228 self.animal_to_place = chicken |
229 print "Selected animal %r" % (self.animal_to_place,) | 229 print "Selected animal %r" % (self.animal_to_place,) |
230 return | 230 return |
231 building = self.get_building(tile_pos) | 231 building = self.get_building(tile_pos) |
232 if building: | 232 if building: |
233 if self.animal_to_place is not None: | 233 self.open_building_dialog(building) |
234 occupant = self.animal_to_place | |
235 if occupant in self.tv.sprites: | |
236 self.tv.sprites.remove(occupant) | |
237 building.add_occupant(occupant) | |
238 print building, building.occupants() | |
239 else: | |
240 self.select_animal_from_building(building) | |
241 return | 234 return |
242 if self.tv.get(tile_pos) == self.GRASSLAND: | 235 if self.tv.get(tile_pos) == self.GRASSLAND: |
243 if self.animal_to_place is not None: | 236 if self.animal_to_place is not None: |
244 occupant = self.animal_to_place | 237 occupant = self.animal_to_place |
245 if occupant.abode is not None: | 238 if occupant.abode is not None: |
246 occupant.abode.remove_occupant(occupant) | 239 occupant.abode.remove_occupant(occupant) |
247 occupant.set_pos(tile_pos) | 240 occupant.set_pos(tile_pos) |
248 | 241 |
249 def select_animal_from_building(self, building): | 242 def open_dialog(self, widget): |
250 """Create dialog for selecting an animal from a building.""" | 243 """Open a dialog for the given widget. Add close button.""" |
251 # XXX: unimplemented | 244 tbl = gui.Table() |
252 print "Selecting animal from building %r" % (building,) | 245 |
246 def close_dialog(): | |
247 self.disp.close(tbl) | |
248 | |
249 close_button = gui.Button("Close") | |
250 close_button.connect(gui.CLICK, close_dialog) | |
251 | |
252 tbl = gui.Table() | |
253 tbl.tr() | |
254 tbl.td(widget, colspan=2) | |
255 tbl.tr() | |
256 tbl.td(gui.Spacer(100, 0)) | |
257 tbl.td(close_button) | |
258 | |
259 self.disp.open(tbl) | |
260 | |
261 def open_building_dialog(self, building): | |
262 """Create dialog for manipulating the contents of a building.""" | |
263 width, height = pygame.display.get_surface().get_size() | |
264 tbl = gui.Table() | |
265 for row in range(building.size[0]): | |
266 tbl.tr() | |
267 for col in range(building.size[1]): | |
268 button = gui.Button("%s, %s" % (row, col)) | |
269 tbl.td(button) | |
270 | |
271 self.open_dialog(tbl) | |
253 | 272 |
254 def buy_fence(self, tile_pos): | 273 def buy_fence(self, tile_pos): |
255 this_tile = self.tv.get(tile_pos) | 274 this_tile = self.tv.get(tile_pos) |
256 if this_tile not in [self.GRASSLAND, self.BROKEN_FENCE]: | 275 if this_tile not in [self.GRASSLAND, self.BROKEN_FENCE]: |
257 return | 276 return |
328 for chicken in self.chickens: | 347 for chicken in self.chickens: |
329 chicken.attack(self) | 348 chicken.attack(self) |
330 | 349 |
331 def add_chicken(self, chicken): | 350 def add_chicken(self, chicken): |
332 self.chickens.append(chicken) | 351 self.chickens.append(chicken) |
333 self.tv.sprites.append(chicken) | 352 if chicken.outside(): |
353 self.tv.sprites.append(chicken) | |
334 self.toolbar.update_chicken_counter(len(self.chickens)) | 354 self.toolbar.update_chicken_counter(len(self.chickens)) |
335 | 355 |
336 def add_fox(self, fox): | 356 def add_fox(self, fox): |
337 self.foxes.append(fox) | 357 self.foxes.append(fox) |
338 self.tv.sprites.append(fox) | 358 self.tv.sprites.append(fox) |
354 self.tv.sprites.remove(fox) | 374 self.tv.sprites.remove(fox) |
355 | 375 |
356 def remove_chicken(self, chick): | 376 def remove_chicken(self, chick): |
357 if chick in self.chickens: | 377 if chick in self.chickens: |
358 self.chickens.remove(chick) | 378 self.chickens.remove(chick) |
359 self.tv.sprites.remove(chick) | 379 if chick.outside(): |
380 self.tv.sprites.remove(chick) | |
360 self.toolbar.update_chicken_counter(len(self.chickens)) | 381 self.toolbar.update_chicken_counter(len(self.chickens)) |
361 | 382 |
362 def remove_building(self, building): | 383 def remove_building(self, building): |
363 if building in self.buildings: | 384 if building in self.buildings: |
364 self.buildings.remove(building) | 385 self.buildings.remove(building) |