/** * Renvoie l'altitude moyenne des voisins, sans les hexas de la couronne et sans les hexas d'altitude 0 * @param Hexa $hexa * @param HexaCollection $couronne * @return float */ public function altitudeMoyenneSansCouronne(Hexa $hexa, HexaCollection $couronne) { $altitudes = array(); for ($angle = 0; $angle <= 5; $angle++) { $voisin = $hexa->getVoisin($angle); if (!is_null($voisin) && !$couronne->exists($voisin) && $voisin->getAltitude() > 0) { $altitudes[] = $voisin->getAltitude(); } } if (count($altitudes) == 0) { return 0; } return array_sum($altitudes) / count($altitudes); }
/** * Renvoie le coin supérieur gauche de la carte * @return Hexa */ public function coinSupGauche() { if (is_null($this->coinSupGauche)) { // Recalage en Y du centre pour les bords while ($this->centre->getY() < floor($this->hauteur / 2)) { if (fmod($this->centre->getY(), 2) == 1) { // Y impair $this->centre = $this->centre->getVoisin(5); } else { // Y pair $this->centre = $this->centre->getVoisin(4); } } while ($this->partie->getHauteur() - 1 - floor($this->hauteur / 2) < $this->centre->getY()) { if (fmod($this->centre->getY(), 2) == 1) { // Y impair $this->centre = $this->centre->getVoisin(1); } else { // Y pair $this->centre = $this->centre->getVoisin(2); } } // Recherche Y du coin $coin = $this->centre; while ($coin->getY() > $this->centre->getY() - ($this->hauteur / 2 - (1 - fmod($this->hauteur, 2) / 2))) { if (fmod($coin->getY(), 2) == 1) { // Y impair $coin = $coin->getVoisin(1); } else { // Y pair $coin = $coin->getVoisin(2); } } // Recherche du X du coin for ($i = 1; $i <= $this->largeur / 2 - (1 - fmod($this->largeur, 2) / 2); $i++) { $coin = $coin->getVoisin(3); } $this->coinSupGauche = $coin; } return $this->coinSupGauche; }