Example #1
0
class Rabbit:
  def __init__(self):
    self.age = 0
    self.dead = False
    self.position = Coordinate()
    self.move_behavior = MoveBehavior(self)
    self.breed_behavior = BreedBehavior(self, 3)

  def __repr__(self):
    return "R(%d)" % self.age

  def __str__(self):
    return "R(%d)" % self.age

  def update(self, game):
    if self.dead:
      return

    self.age += 1

    self.move_behavior.run(game)
    self.breed_behavior.run(game)

  def die(self, game):
    self.dead = True
    game.world_map.remove(self)
Example #2
0
class Fox:
  def __init__(self):
    self.age = 0
    self.dead = False
    self.position = Coordinate()
    self.move_behavior = MoveBehavior(self)
    self.eat_behavior = EatBehavior(self, [Rabbit])
    self.breed_behavior = BreedBehavior(self, 8)
    self.starve_behavior = StarveBehavior(self, 3)

  def __repr__(self):
    return "F(%d,%d)" % (self.age, self.starve)

  def __str__(self):
    return "F(%d,%d)" % (self.age, self.starve)

  def update(self, game):
    if self.dead:
      return

    self.age += 1

    success = self.eat_behavior.run(game)
    if not success:
      self.move_behavior.run(game)
    self.breed_behavior.run(game)
    self.starve_behavior.run(game)

  def die(self, game):
    self.dead = True
    game.world_map.remove(self)
Example #3
0
 def __init__(self):
   self.age = 0
   self.dead = False
   self.position = Coordinate()
   self.move_behavior = MoveBehavior(self)
   self.eat_behavior = EatBehavior(self, [Rabbit])
   self.breed_behavior = BreedBehavior(self, 8)
   self.starve_behavior = StarveBehavior(self, 3)
Example #4
0
 def __init__(self):
   self.age = 0
   self.dead = False
   self.position = Coordinate()
   self.move_behavior = MoveBehavior(self)
   self.breed_behavior = BreedBehavior(self, 3)