Beispiel #1
0
def test_move_actor():
    actor = Actor(0)
    enemy = Actor(1)
    actor.location[0] = 20
    actor.location[1] = 10
    enemy.location[0] = 10
    enemy.location[1] = 50
    actor.speed = 30
    actor.move_actor(enemy)
    assert actor.location[
        0] == 10  # 20 - 30 = -10 but enemy is at 10 so stop at 10
    assert actor.location[1] == 40  # 10 + 30 = 40
    actor.location[0] = 100
    actor.location[1] = 100
    actor.move_actor(enemy)
    assert actor.location[0] == 70
    assert actor.location[1] == 70
 def move_actor(self, enemy):
     if self.runs >= self.max_runs(
     ):  # Limit how often a hobbit can run away
         self.runs = 0
         Actor.move_actor(self, enemy)
     elif self.fear > enemy.strength and self.strength < enemy.health_points and self.dependence > 50:
         # X Movement
         if enemy.location[0] > self.location[0]:
             self.location[0] = self.location[0] - self.speed
         elif enemy.location[0] < self.location[0]:
             self.location[0] = self.location[0] + self.speed
         # Y Movement
         if enemy.location[1] > self.location[1]:
             self.location[1] = self.location[1] - self.speed
         elif enemy.location[1] < self.location[1]:
             self.location[1] = self.location[1] + self.speed
         self.runs += 1
     else:
         Actor.move_actor(self, enemy)
     # Actor.keep_in(self)
     # If a hobbit runs out off the battlefield they are considered dead to us
     self.seppuku()
     enemy.take_damage(Actor.fight(self, enemy))