/**
  * @param Hexa $hexa1
  * @param Hexa $hexa2
  * @return Frontiere
  */
 public function createIfNotExists(Hexa $hexa1, Hexa $hexa2)
 {
     $frontiere = $this->getByIndex(Partie::getIndexCouple($hexa1, $hexa2));
     if (is_null($frontiere)) {
         $frontiere = new Frontiere($hexa1, $hexa2);
         $this->append($frontiere);
     }
     return $frontiere;
 }
Esempio n. 2
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;
 }
 /**
  * Renvoie les Infrastructures liés au Partie fourni
  * @var Partie $partie
  * @return InfrastructureCollection
  */
 public static function getByPartie(Partie $partie)
 {
     $req = "SELECT * from infrastructure WHERE idHexa IN (SELECT hexa.idHexa FROM hexa WHERE hexa.idPartie = " . $partie->getIdPartie() . ")";
     return DbHandler::collFromQuery($req, 'Infrastructure', 'InfrastructureCollection');
 }
Esempio n. 4
0
 /**
  * Renvoie les Batiments à modifier pour la partie fournie
  * @var Partie $partie
  * @return BatimentCollection
  */
 public static function getAModifierDePartie(Partie $partie)
 {
     $req = "SELECT * from batiment WHERE idHexa IN (SELECT hexa.idHexa FROM hexa WHERE hexa.idPartie = " . $partie->getIdPartie() . ") AND enConstruction in (-1,1) ORDER BY niveau ASC";
     return DbHandler::collFromQuery($req, 'Batiment', 'BatimentCollection');
 }
Esempio n. 5
0
 /**
  * Renvoie les Qgs liés au Partie fourni
  * @var Partie $partie
  * @return QgCollection
  */
 public static function getByPartie(Partie $partie)
 {
     $req = "SELECT * from qg WHERE idJoueur IN (SELECT joueur.IdJoueur FROM joueur WHERE joueur.idPartie = " . $partie->getIdPartie() . ")";
     return DbHandler::collFromQuery($req, 'Qg', 'QgCollection');
 }
Esempio n. 6
0
 /**
  * Renvoie les Joueur liées à un Partie
  * @param Partie $partie
  * @return JoueurCollection
  */
 public static function getByPartie(Partie $partie)
 {
     $req = "SELECT * FROM joueur WHERE idPartie = '" . $partie->getIdPartie() . "';";
     return DbHandler::collFromQuery($req, 'Joueur', 'JoueurCollection');
 }
Esempio n. 7
0
 /**
  * @return string
  */
 public function getIndex()
 {
     return Partie::getIndexCouple($this->getHexa1(), $this->getHexa2());
 }
Esempio n. 8
0
 /**
  * Renvoie l'Id minimum des hexas de la partie
  * @param Partie $partie
  * @return int
  */
 public static function idHexaMini(Partie $partie)
 {
     $req = "SELECT MIN(idHexa) as mini FROM hexa WHERE idPartie = " . $partie->getId() . ";";
     $res = DbHandler::query($req);
     if (is_null($res[0]['mini'])) {
         $req = "SELECT MAX(idHexa) as mini FROM hexa;";
         $res = DbHandler::query($req);
         $res[0]['mini']++;
     }
     return $res[0]['mini'];
 }
Esempio n. 9
0
 /**
  * Renvoie les Unites à modifier pour la partie fournie
  * @var Partie $partie
  * @return UniteCollection
  */
 public static function getAModifierDePartie(Partie $partie)
 {
     $req = "SELECT * from unite WHERE idHexaConstruit IN (SELECT hexa.idHexa FROM hexa WHERE hexa.idPartie = " . $partie->getIdPartie() . ") AND enConstruction in (-1,1);";
     return DbHandler::collFromQuery($req, 'Unite', 'UniteCollection');
 }
Esempio n. 10
0
 /**
  * Renvoie le joueur de l'utilisateur lié à une partie
  * @param Partie $partie
  * @return Joueur
  */
 public function joueurDePartie(Partie $partie)
 {
     foreach ($this->getJoueurs() as $joueur) {
         /** @var Joueur $joueur */
         if ($joueur->getIdPartie() == $partie->getIdPartie()) {
             return $joueur;
         }
     }
     return null;
 }