/** * Eliminazione elemento da Matrice * @param FishInterface $fish * @return null */ public function delete(FishInterface $fish) { $pos = $this->matrix->search($fish); if ($pos == null) { return null; } $this->population = $this->copyArrayWithoutFish($fish); $this->matrix->put(self::OCEAN, $pos); }
/** * Faccio passare il tempo per il pesce * * @param FishInterface $fish * @param Position $current */ protected function aging(FishInterface $fish, Position $current) { $fish->setHealth($fish->getHealth() - 1); $sons = $fish->getChildren(); // la vita è zero: muore if ($fish->getHealth() == 0) { $this->worldMap->put(null, $current); unset($fish); } // se ci sono dei figli: gli aggiungo alla mappa foreach ($sons as $son) { $sonPos = $this->getFreePosition($current); if ($sonPos !== null) { $this->worldMap->put($son, $sonPos); } } }