Mercurial > rinkhals
comparison gamelib/gameboard.py @ 84:5494af02a0e8
Chickens with rifles!
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Tue, 01 Sep 2009 21:31:08 +0000 |
parents | 9bd2c22e1746 |
children | bea1b9364583 |
comparison
equal
deleted
inserted
replaced
83:9bd2c22e1746 | 84:5494af02a0e8 |
---|---|
8 import tiles | 8 import tiles |
9 import icons | 9 import icons |
10 import constants | 10 import constants |
11 import buildings | 11 import buildings |
12 import animal | 12 import animal |
13 import equipment | |
13 | 14 |
14 class OpaqueLabel(gui.Label): | 15 class OpaqueLabel(gui.Label): |
15 def paint(self, s): | 16 def paint(self, s): |
16 s.fill(self.style.background) | 17 s.fill(self.style.background) |
17 gui.Label.paint(self, s) | 18 gui.Label.paint(self, s) |
246 else: | 247 else: |
247 self.disp.event(e) | 248 self.disp.event(e) |
248 | 249 |
249 def clear_foxes(self): | 250 def clear_foxes(self): |
250 for fox in self.foxes: | 251 for fox in self.foxes: |
251 self.tv.sprites.remove(fox) | |
252 # Any foxes that didn't make it to the woods are automatically | 252 # Any foxes that didn't make it to the woods are automatically |
253 # killed | 253 # killed |
254 if self.in_bounds(fox.pos) and self.tv.get(fox.pos.to_tuple()) \ | 254 if self.in_bounds(fox.pos) and self.tv.get(fox.pos.to_tuple()) \ |
255 != self.WOODLAND: | 255 != self.WOODLAND: |
256 self.killed_foxes += 1 | 256 self.kill_fox(fox) |
257 self.toolbar.update_fox_counter(self.killed_foxes) | 257 else: |
258 self.add_cash(constants.SELL_PRICE_DEAD_FOX) | 258 self.tv.sprites.remove(fox) |
259 self.foxes = [] # Remove all the foxes | 259 self.foxes = [] # Remove all the foxes |
260 | 260 |
261 def move_foxes(self): | 261 def move_foxes(self): |
262 for fox in self.foxes: | 262 for fox in self.foxes: |
263 fox.move(self) | 263 fox.move(self) |
264 for chicken in self.chickens: | |
265 chicken.attack(self) | |
264 | 266 |
265 def add_chicken(self, chicken): | 267 def add_chicken(self, chicken): |
266 self.chickens.append(chicken) | 268 self.chickens.append(chicken) |
267 self.tv.sprites.append(chicken) | 269 self.tv.sprites.append(chicken) |
268 self.toolbar.update_chicken_counter(len(self.chickens)) | 270 self.toolbar.update_chicken_counter(len(self.chickens)) |
272 self.tv.sprites.append(fox) | 274 self.tv.sprites.append(fox) |
273 | 275 |
274 def add_building(self, building): | 276 def add_building(self, building): |
275 self.buildings.append(building) | 277 self.buildings.append(building) |
276 self.tv.sprites.append(building) | 278 self.tv.sprites.append(building) |
279 | |
280 def kill_fox(self, fox): | |
281 if fox in self.foxes: | |
282 self.killed_foxes += 1 | |
283 self.toolbar.update_fox_counter(self.killed_foxes) | |
284 self.add_cash(constants.SELL_PRICE_DEAD_FOX) | |
285 self.remove_fox(fox) | |
277 | 286 |
278 def remove_fox(self, fox): | 287 def remove_fox(self, fox): |
279 if fox in self.foxes: | 288 if fox in self.foxes: |
280 self.foxes.remove(fox) | 289 self.foxes.remove(fox) |
281 self.tv.sprites.remove(fox) | 290 self.tv.sprites.remove(fox) |
329 # Fence | 338 # Fence |
330 roll = 10 | 339 roll = 10 |
331 if roll == 1: | 340 if roll == 1: |
332 # Create a chicken | 341 # Create a chicken |
333 chick = animal.Chicken((x, y)) | 342 chick = animal.Chicken((x, y)) |
343 if random.randint(0, 1) == 0: | |
344 chick.equip(equipment.Rifle()) | |
334 self.add_chicken(chick) | 345 self.add_chicken(chick) |
335 x += 1 | 346 x += 1 |
336 | 347 |
337 def spawn_foxes(self): | 348 def spawn_foxes(self): |
338 """The foxes come at night, and this is where they come from.""" | 349 """The foxes come at night, and this is where they come from.""" |