Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * Dit quel est l'angle de voisinage de la case demandée
  * @param Hexa $hexa
  * @return int ou null si la case n'est pas voisine de this
  */
 public function quelVoisin(Hexa $hexa)
 {
     $voisins = array();
     for ($angle = 0; $angle <= 5; $angle++) {
         $coords = self::getCoordsVoisins($this->getX(), $this->getY(), $angle);
         $coords = $this->getPartie()->coordsCorrigees($coords[0], $coords[1]);
         if (!is_null($coords)) {
             $voisins[$coords[0] . '_' . $coords[1]] = $angle;
         }
     }
     if (isset($voisins[$hexa->getX() . '_' . $hexa->getY()])) {
         return $voisins[$hexa->getX() . '_' . $hexa->getY()];
     }
     return null;
 }