Changeset 601:23fbf4651f99
- Timestamp:
- Dec 6, 2009, 10:11:37 AM (11 years ago)
- Branch:
- default
- Convert:
- svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68/trunk/rinkhals@606
- Location:
- gamelib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
gamelib/animal.py
r557 r601 229 229 """See if the chicken lays an egg""" 230 230 if self.abode and self.abode.building.HENHOUSE: 231 # TODO: Find a cleaner way to do this 232 fertilised = False 233 for bird in self.abode.building.occupants(): 234 if getattr(bird, 'ROOSTER', None): 235 fertilised = True 231 236 if not self.eggs: 232 237 for x in range(random.randint(1, 4)): 233 self.eggs.append(Egg(self.pos, self.gameboard ))238 self.eggs.append(Egg(self.pos, self.gameboard, fertilised=fertilised)) 234 239 self.equip(equipment.NestEgg()) 235 240 self.gameboard.eggs += self.get_num_eggs() … … 296 301 weapon.refresh_ammo() 297 302 303 304 class Rooster(Chicken): 305 """A rooster""" 306 307 IMAGE_FILE = 'sprites/rooster.png' 308 ROOSTER = True 309 310 AGGRESSION = 50 311 312 def lay(self): 313 # Roosters don't lay eggs. 314 pass 315 316 def start_night(self): 317 Chicken.start_night(self) 318 self._manly_fight() 319 320 def _manly_fight(self): 321 if self.abode: 322 for rival in [occ for occ in self.abode.building.occupants() 323 if getattr(occ, 'ROOSTER', False)]: 324 if random.randint(1, 100) <= self.AGGRESSION: 325 rival.damage() 326 327 298 328 class Egg(Animal): 299 329 """An egg""" … … 301 331 IMAGE_FILE = 'sprites/equip_egg.png' 302 332 303 SIMPLIFY = Animal.SIMPLIFY + ['timer' ]304 305 def __init__(self, pos, gameboard ):333 SIMPLIFY = Animal.SIMPLIFY + ['timer', 'fertilised'] 334 335 def __init__(self, pos, gameboard, fertilised=False): 306 336 Animal.__init__(self, pos, gameboard) 337 self.fertilised = fertilised 307 338 self.timer = 2 308 339 … … 311 342 def hatch(self): 312 343 self.timer -= 1 313 if self.timer == 0 :314 return Chicken(self.pos, self.gameboard)344 if self.timer == 0 and self.fertilised: 345 return random.choice([Chicken, Rooster])(self.pos, self.gameboard) 315 346 return None 347 316 348 317 349 class Fox(Animal): -
gamelib/gameboard.py
r599 r601 1095 1095 def add_start_chickens(self, _map, tile, value): 1096 1096 """Add chickens as specified by the code layer""" 1097 chick = animal.Chicken((tile.tx, tile.ty), self)1097 chick = random.choice([animal.Chicken, animal.Rooster])((tile.tx, tile.ty), self) 1098 1098 for equip_cls in equipment.EQUIP_MAP[value]: 1099 1099 item = equip_cls()
Note: See TracChangeset
for help on using the changeset viewer.