示例#1
0
 /**
  * Renvoie les Parties liés à une collection de Hexas
  * @param HexaCollection $hexas
  * @return PartieCollection
  */
 public static function getFromHexas(HexaCollection $hexas)
 {
     $ids = $hexas->getIdParties();
     if (!$ids) {
         return new PartieCollection();
     }
     $req = "SELECT * FROM partie WHERE idPartie IN (" . $ids . ");";
     return DbHandler::collFromQuery($req, 'Partie', 'PartieCollection');
 }
 /**
  * Renvoie les Batiments liés aux Hexas de la collection fournie en paramètre
  * @param HexaCollection $hexas
  * @return BatimentCollection
  */
 public static function getFromHexas(HexaCollection $hexas)
 {
     $ids = $hexas->getIdsStr();
     if (!$ids) {
         return new BatimentCollection();
     }
     $req = "SELECT * FROM batiment WHERE idHexa IN (" . $ids . ");";
     return DbHandler::collFromQuery($req, 'Batiment', 'BatimentCollection');
 }
示例#3
0
 /**
  * Renvoie les Visibles liés aux Hexas de la collection fournie en paramètre
  * @param HexaCollection $hexas
  * @param Joueur $joueur Ne fournit que les visiles de ce joueur pour la collection d'hexas
  * @return VisibleCollection
  */
 public static function getFromHexas(HexaCollection $hexas, Joueur $joueur = null)
 {
     $ids = $hexas->getIdsStr();
     if (!$ids) {
         return new VisibleCollection();
     }
     $req = "SELECT * FROM visible WHERE idHexa IN (" . $ids . ")";
     if (!is_null($joueur)) {
         $req .= " AND idJoueur = " . $joueur->getId();
     }
     $req .= ";";
     return DbHandler::collFromQuery($req, 'Visible', 'VisibleCollection');
 }
示例#4
0
 /**
  * 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);
 }
示例#5
0
 /**
  * Renvoie les hexagones dans l'ordre d'un balayage
  * @return HexaCollection
  */
 public function buildHexas()
 {
     $this->hexas = new HexaCollection();
     $debutLigne = $this->coinSupGauche();
     $rivieres = array();
     for ($y = 1; $y <= $this->hauteur; $y++) {
         $current = $debutLigne;
         for ($x = 0; $x < $this->largeur; $x++) {
             $this->hexas->ajout($current);
             // Rivères
             foreach ($current->getRivieres() as $riviere) {
                 /** @var Riviere $riviere */
                 if (!isset($rivieres[$riviere->getId()])) {
                     $this->rivieres->ajout($riviere);
                     $rivieres[$riviere->getId()] = true;
                 }
             }
             // Visibles
             $this->ajoutVisiblesHexa($current);
             $current = $current->getVoisin(0);
         }
         if (fmod($debutLigne->getY(), 2) == 1) {
             // Y impair
             $debutLigne = $debutLigne->getVoisin(5);
         } else {
             // Y pair
             $debutLigne = $debutLigne->getVoisin(4);
         }
     }
 }
示例#6
0
 /**
  * Renvoie les Hexas liés à l'objet
  * @return HexaCollection|Hexa[]
  */
 public function getHexas()
 {
     if (is_null($this->cacheHexas)) {
         $this->cacheHexas = HexaBusiness::getByPartie($this);
         $this->cacheHexas->store();
     }
     return $this->cacheHexas;
 }
示例#7
0
 /**
  * Renvoie les Trajectoires entières qui ont au moins 1 case dans $hexas
  * @param HexaCollection $hexas
  * @return TrajCollection
  */
 public static function getEntieresFromHexas(HexaCollection $hexas)
 {
     $ids = $hexas->getIdsStr();
     if (!$ids) {
         return new TrajCollection();
     }
     $req = "SELECT * FROM traj WHERE idQg IN (SELECT DISTINCT(sousTraj.idQg) FROM traj sousTraj WHERE sousTraj.idHexa IN (" . $ids . "));";
     return DbHandler::collFromQuery($req, 'Traj', 'TrajCollection');
 }
示例#8
0
 /**
  *
  * @param Noeud $noeud
  * @return bool
  */
 public function objectifAtteint(Noeud $noeud)
 {
     if ($this->hexasInterdits->exists($noeud->getHexa())) {
         return false;
     }
     if ($this->but == self::BUT_RAVITAILLEMENT) {
         if ($noeud->getHexa()->getIdJoueur() == $this->pov->getId()) {
             return true;
         }
     } elseif ($this->but == self::BUT_COMMERCE) {
         if ($noeud->getHexa()->getIdTerritoire() == $this->pov->getId()) {
             return true;
         }
     } elseif ($this->but == self::BUT_VILLE_ENNEMIE) {
         if ($noeud->getHexa()->getIdJoueur() == $this->pov->getId()) {
             return true;
         }
     }
     return false;
 }
 /**
  * Renvoie les Infrastructures liés aux Hexas de la collection fournie en paramètre
  * @param HexaCollection $hexas
  * @return InfrastructureCollection
  */
 public static function getFromHexas(HexaCollection $hexas)
 {
     return self::getFromIdsHexas($hexas->getIdsStr(true));
 }
 /**
  * Renvoie les Productions liés aux Hexas de la collection fournie
  * @var HexaCollection $hexas
  * @return ProductionCollection
  */
 public static function getFromHexas(HexaCollection $hexas)
 {
     $req = "SELECT * from production WHERE idBatiment IN (SELECT batiment.idBatiment FROM batiment WHERE batiment.idHexa IN (" . $hexas->getIdsStr() . "))";
     return DbHandler::collFromQuery($req, 'Production', 'ProductionCollection');
 }
示例#11
0
 /**
  * Renvoie les Joueurs liés à une collection de Hexas
  * @param HexaCollection $hexas
  * @return JoueurCollection
  */
 public static function getFromHexasTerritoire(HexaCollection $hexas)
 {
     $ids = $hexas->getIdTerritoires();
     if (!$ids) {
         return new JoueurCollection();
     }
     $req = "SELECT * FROM joueur WHERE idJoueur IN (" . $ids . ");";
     return DbHandler::collFromQuery($req, 'Joueur', 'JoueurCollection');
 }
 /**
  * Renvoie les Competences liés aux Hexas de la collection fournie
  * @var HexaCollection $hexas
  * @return CompetenceCollection
  */
 public static function getFromHexas(HexaCollection $hexas)
 {
     $req = "SELECT * from competence WHERE idQg IN (SELECT qg.idQg FROM qg WHERE qg.idHexa IN (" . $hexas->getIdsStr() . "))";
     return DbHandler::collFromQuery($req, 'Competence', 'CompetenceCollection');
 }
 /**
  * Renvoie les Utilisateurs liés aux Hexas de la collection fournie
  * @var HexaCollection $hexas
  * @return UtilisateurCollection
  */
 public static function getFromHexas(HexaCollection $hexas)
 {
     $req = "SELECT * FROM utilisateur WHERE idUtilisateur IN (SELECT joueur.idUtilisateur FROM joueur WHERE joueur.idTerritoire IN (" . $hexas->getIdTerritoires() . "))";
     return DbHandler::collFromQuery($req, 'Utilisateur', 'UtilisateurCollection');
 }
示例#14
0
 /**
  * Choisit un Hexa dans les cases voisines pour un recul forcé
  * @return Hexa
  */
 public function choixHexaReculForce()
 {
     $destPossibles = new HexaCollection();
     foreach ($this->getPosition()->voisins() as $hexa) {
         /** @var Hexa $hexa */
         if ($this->getQg()->canPass($this->getPosition(), $hexa)) {
             $destPossibles->ajout($hexa);
         }
     }
     $destPossibles->uasort('fr\\gilman\\nj\\common\\bb\\business\\HexaBusiness::choixReculForce');
     return $destPossibles->getFirstElement();
 }
示例#15
0
 /**
  * Renvoie les hexas dans la couronne à la distance $rayon de la case et tous ceux à l'intérieur
  * @param $rayon
  * @return HexaCollection|Hexa[]
  */
 public function getCouronnePleine($rayon)
 {
     $ret = new HexaCollection();
     $ret->ajout($this);
     for ($i = 1; $i <= $rayon; $i++) {
         foreach ($this->getCouronne($i) as $hexa) {
             $ret->ajout($hexa);
         }
     }
     return $ret;
 }