/** * @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; }
/** * 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'); }
/** * 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'); }
/** * 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'); }
/** * 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'); }
/** * @return string */ public function getIndex() { return Partie::getIndexCouple($this->getHexa1(), $this->getHexa2()); }
/** * 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']; }
/** * 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'); }
/** * 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; }