/**
  * Ajoute un visible à la collection à partir d'une joueur et d'un hexa
  * @param Joueur $joueur
  * @param Hexa $hexa
  */
 public function addByJH(Joueur $joueur, Hexa $hexa)
 {
     $visible = new Visible();
     $visible->setIdJoueur($joueur->getId());
     $visible->setIdHexa($hexa->getId());
     $this->ajout($visible);
 }
Esempio n. 2
0
 /**
  * Ajoute à la carte les objets visibles reliés à un hexa
  * @param Hexa $hexa
  * @return void
  */
 protected function ajoutVisiblesHexa(Hexa $hexa)
 {
     $this->visiblesGeres = true;
     if ($this->joueur->getVisibles()->hexaExists($hexa)) {
         // Qgs
         foreach ($hexa->getQgs() as $qg) {
             /** @var Qg $qg */
             $this->qgs->ajout($qg);
             // Unites
             foreach ($qg->getUnites() as $unite) {
                 /** @var Unite $unite */
                 $this->unites->ajout($unite);
             }
         }
     }
 }
Esempio n. 3
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 au Joueur fourni
  * @var Joueur $joueur
  * @return InfrastructureCollection
  */
 public static function getByJoueur(Joueur $joueur)
 {
     $req = "SELECT * from infrastructure WHERE idHexa IN (SELECT hexa.idHexa FROM hexa WHERE hexa.idTerritoire = " . $joueur->getIdJoueur() . ")";
     return DbHandler::collFromQuery($req, 'Infrastructure', 'InfrastructureCollection');
 }
Esempio n. 5
0
 /**
  * Inscrit un joueur à la partie
  * @param Joueur $joueur
  * @return bool Succès de l'inscription. false si pas possible
  */
 public function inscrireJoueur(Joueur $joueur)
 {
     $ret = false;
     $caseDepart = null;
     foreach ($this->getHexas()->shuffle() as $hexa) {
         /** @var Hexa $hexa */
         if (Terrains::hexaAutoriseDemarrage($hexa)) {
             foreach ($hexa->voisins() as $voisin) {
                 /** @var Hexa $voisin */
                 if ($voisin->getIdTerritoire() != 0 || $voisin->getIdJoueur() != 0) {
                     continue 2;
                 }
             }
             // Données de la case capitale et de ses voisines
             $hexa->setIdJoueur($joueur->getId());
             $hexa->setIdTerritoire($joueur->getId());
             foreach ($hexa->voisins() as $voisin) {
                 /** @var Hexa $voisin */
                 $voisin->setIdTerritoire($joueur->getId());
                 $voisin->save();
             }
             $hexa->setNom($joueur->getNom() . ' Prime');
             $hexa->setPopulation(1);
             $hexa->save();
             // Données du joueur
             $joueur->setIdPartie($this->getId());
             $joueur->setTresor(1000);
             $joueur->setIdCapitale($hexa->getId());
             $joueur->save();
             $ret = true;
             break;
         }
     }
     return $ret;
 }
Esempio n. 6
0
 /**
  * Dir si le joueur fourni en paramètre a le droit de voir la mission et la trajectoire du qg
  * @param Joueur $joueur
  * @return bool
  */
 public function droitVoirTraj(Joueur $joueur)
 {
     return $joueur->getId() == $this->getIdJoueur();
 }
Esempio n. 7
0
 /**
  * Renvoie les Batiments liés au Joueur fourni
  * @var Joueur $joueur
  * @return BatimentCollection
  */
 public static function getByJoueur(Joueur $joueur)
 {
     $req = "SELECT * from batiment WHERE idHexa IN (SELECT hexa.idHexa FROM hexa WHERE hexa.IdJoueur = " . $joueur->getIdJoueur() . ")";
     return DbHandler::collFromQuery($req, 'Batiment', 'BatimentCollection');
 }
Esempio n. 8
0
 /**
  * Dit si l'unité peut être débandée ou sa production annulée par un joueur
  * @param Joueur $joueur
  * @return bool
  */
 public function peutDetruire(Joueur $joueur)
 {
     if ($this->getIdQg() == 0 && HexaStore::getById($this->getIdHexaConstruit())->getIdJoueur() == $joueur->getId()) {
         return true;
     } elseif ($this->getIdQg() && $this->getQg()->getIdJoueur() == $joueur->getId()) {
         return true;
     } else {
         return false;
     }
 }
Esempio n. 9
0
 /**
  * @param Joueur $joueur
  * @return bool
  */
 public function isEnnemi(Joueur $joueur)
 {
     return $joueur->getId() != $this->getId();
 }
Esempio n. 10
0
 /**
  * Renvoie les Qg liées à un Joueur
  * @param Joueur $joueur
  * @return QgCollection
  */
 public static function getByJoueur(Joueur $joueur)
 {
     $req = "SELECT * FROM qg WHERE idJoueur = '" . $joueur->getIdJoueur() . "';";
     return DbHandler::collFromQuery($req, 'Qg', 'QgCollection');
 }
Esempio n. 11
0
 /**
  * Renvoie les Competences liés au Joueur fourni
  * @var Joueur $joueur
  * @return CompetenceCollection
  */
 public static function getByJoueur(Joueur $joueur)
 {
     $req = "SELECT * from competence WHERE idQg IN (SELECT qg.idQg FROM qg WHERE qg.IdJoueur = " . $joueur->getIdJoueur() . ")";
     return DbHandler::collFromQuery($req, 'Competence', 'CompetenceCollection');
 }
Esempio n. 12
0
 /**
  * Dit si l'infra est destructible par un joueur
  * @param Joueur $joueur
  * @return bool
  */
 public function destructiblePar(Joueur $joueur)
 {
     if (!$this->getIdHexa2()) {
         if ($this->getHexa()->getIdTerritoire() == $joueur->getId() && !$this->getHexa()->hasQg(true)) {
             return true;
         } elseif ($this->getHexa()->getIdTerritoire() != $joueur->getId() && $this->getHexa()->hasQg()) {
             return true;
         }
     } else {
         if ($this->getHexa()->getIdTerritoire() == $joueur->getId() && $this->getHexa2()->getIdTerritoire() == $joueur->getId()) {
             // Les 2 cases sont le territoire du joueur
             if (!$this->getHexa()->hasQg(true) && !$this->getHexa2()->hasQg(true)) {
                 return true;
             }
         } elseif ($this->getHexa()->getIdTerritoire() == $joueur->getId() && $this->getHexa2()->getIdTerritoire() == 0 || $this->getHexa()->getIdTerritoire() == 0 && $this->getHexa2()->getIdTerritoire() == $joueur->getId()) {
             // Une des 2 cases n'a pas de propriétaire
             if (!$this->getHexa()->hasQg(true) && !$this->getHexa2()->hasQg(true)) {
                 return true;
             }
         } else {
             if (($this->getHexa()->hasQg() || $this->getHexa2()->hasQg()) && !($this->getHexa()->hasQg(true) || $this->getHexa2()->hasQg(true))) {
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 13
0
 /**
  * Renvoie les Hexa territoire d'un Joueur
  * @param Joueur $joueur
  * @return HexaCollection
  */
 public static function getByJoueurTerritoire(Joueur $joueur)
 {
     $req = "SELECT * FROM hexa WHERE idTerritoire = '" . $joueur->getIdJoueur() . "';";
     return DbHandler::collFromQuery($req, 'Hexa', 'HexaCollection');
 }
Esempio n. 14
0
 /**
  * Renvoie la même collection mais avec seulement les qgs du joueur fourni en paramètre
  * @param Joueur $joueur
  * @return QgCollection
  */
 public function filtreeParJoueur(Joueur $joueur)
 {
     if (!isset($this->cacheFiltreParJoueur[$joueur->getId()])) {
         $this->cacheFiltreParJoueur[$joueur->getId()] = new QgCollection();
         foreach ($this as $qg) {
             /** @var Qg $qg */
             if ($qg->getIdJoueur() == $joueur->getId()) {
                 $this->cacheFiltreParJoueur[$joueur->getId()]->ajout($qg);
             }
         }
     }
     return $this->cacheFiltreParJoueur[$joueur->getId()];
 }
Esempio n. 15
0
 /**
  * Crée un Joueur lié à ce Utilisateur
  * @return Joueur
  */
 public function createJoueur()
 {
     $joueur = new Joueur();
     $joueur->setIdUtilisateur($this->getIdUtilisateur());
     return $joueur;
 }
Esempio n. 16
0
 /**
  * Dit si la case est en territoire ennemi
  * @param Joueur $joueur
  * @return bool
  */
 public function isEnnemi(Joueur $joueur)
 {
     return $this->getIdTerritoire() != $joueur->getId();
 }