Example #1
0
 private function eat(Animal $prey)
 {
     $locationPrey = $prey->getLocation();
     $location = $this->getLocation();
     if ($locationPrey["x"] == $location["x"] && $locationPrey["y"] == $location["y"]) {
         $field = $this->getField();
         $field->deleteAnimalFromField($prey);
         $this->sleep = true;
         $this->countTurns = 8;
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 private function goAwayFromNaturalEnemies(Animal $animalEnemies)
 {
     $location = $this->getLocation();
     $direction = mt_rand(self::DIRECTION_FIRST, self::DIRECTION_SECOND);
     $locationEnemies = $animalEnemies->getLocation();
     switch (true) {
         // Кот вверху и слева
         case $locationEnemies["x"] < $location["x"] && $locationEnemies["y"] < $location["y"]:
             if ($direction > self::DIRECTION_FIRST) {
                 $this->goRight();
             } else {
                 $this->goDown();
             }
             return;
             break;
             // Кот вверху и справа
         // Кот вверху и справа
         case $locationEnemies["x"] > $location["x"] && $locationEnemies["y"] < $location["y"]:
             if ($direction > self::DIRECTION_FIRST) {
                 $this->goLeft();
             } else {
                 $this->goDown();
             }
             return;
             break;
             // Кот внизу и слева
         // Кот внизу и слева
         case $locationEnemies["x"] < $location["x"] && $locationEnemies["y"] > $location["y"]:
             if ($direction > self::DIRECTION_FIRST) {
                 $this->goRight();
             } else {
                 $this->goUp();
             }
             return;
             break;
             // Кот внизу и справа
         // Кот внизу и справа
         case $locationEnemies["x"] > $location["x"] && $locationEnemies["y"] > $location["y"]:
             if ($direction > self::DIRECTION_FIRST) {
                 $this->goLeft();
             } else {
                 $this->goUp();
             }
             return;
             break;
             // Кот внизу
         // Кот внизу
         case $locationEnemies["x"] == $location["x"] && $locationEnemies["y"] > $location["y"]:
             if ($direction == self::DIRECTION_FIRST) {
                 $this->goUp();
             } elseif ($direction == self::DIRECTION_SECOND) {
                 $this->goLeft();
             } else {
                 $this->goRight();
             }
             return;
             break;
             // Кот вверху
         // Кот вверху
         case $locationEnemies["x"] == $location["x"] && $locationEnemies["y"] < $location["y"]:
             if ($direction == self::DIRECTION_FIRST) {
                 $this->goDown();
             } elseif ($direction == self::DIRECTION_SECOND) {
                 $this->goLeft();
             } else {
                 $this->goRight();
             }
             return;
             break;
             // Кот справо
         // Кот справо
         case $locationEnemies["x"] > $location["x"] && $locationEnemies["y"] == $location["y"]:
             if ($direction == self::DIRECTION_FIRST) {
                 $this->goUp();
             } elseif ($direction == self::DIRECTION_SECOND) {
                 $this->goLeft();
             } else {
                 $this->goDown();
             }
             return;
             break;
             // Кот слева
         // Кот слева
         case $locationEnemies["x"] < $location["x"] && $locationEnemies["y"] == $location["y"]:
             if ($direction == self::DIRECTION_FIRST) {
                 $this->goUp();
             } elseif ($direction == self::DIRECTION_SECOND) {
                 $this->goRight();
             } else {
                 $this->goDown();
             }
             return;
             break;
             // Не видно кота
         // Не видно кота
         default:
             break;
     }
 }