Exemple #1
0
 function construirePont()
 {
     $ret = array('error' => 0, 'errorMsg' => '');
     if (!isset($_POST['idHexa']) || !isset($_POST['angle'])) {
         $ret['error'] = 1;
         $ret['errorMsg'] = 'Champs manquants';
         echo json_encode($ret);
         exit;
     }
     if (!$this->checkDroit(Droit::LOGGE_PARTIE)) {
         $ret['error'] = 2;
         $ret['errorMsg'] = 'Pas le droit';
         echo json_encode($ret);
         exit;
     }
     $hexa = HexaStore::getById($_POST['idHexa']);
     if (is_null($hexa)) {
         $ret['error'] = 2;
         $ret['errorMsg'] = 'Hexa inexistant';
         echo json_encode($ret);
         exit;
     }
     $ret['idHexa'] = $hexa->getId();
     $bonAngle = false;
     $riviereConcernee = null;
     foreach ($hexa->getRivieres() as $riviere) {
         /** @var Riviere $riviere */
         $voisin = null;
         if ($riviere->getIdHexa1() == $hexa->getId()) {
             $voisin = $riviere->getHexa2();
         }
         if ($riviere->getIdHexa2() == $hexa->getId()) {
             $voisin = $riviere->getHexa1();
         }
         if ($hexa->quelVoisin($voisin) == $_POST['angle']) {
             $bonAngle = true;
             $riviereConcernee = $riviere;
             break;
         }
     }
     if (!$bonAngle) {
         $ret['error'] = 3;
         $ret['errorMsg'] = "Cette rivière n'existe pas sur cette case";
         echo json_encode($ret);
         exit;
     }
     $pont = new Infrastructure();
     $pont->setIdHexa($riviereConcernee->getIdHexa1());
     $pont->setIdHexa2($riviereConcernee->getIdHexa2());
     $pont->setEnConstruction(1);
     $pont->setIdType(Infrastructures::PONT);
     if (SessionBusiness::getCookieSession()->getJoueur()->getTresor() < $pont->getPrix()) {
         $ret['error'] = 6;
         $ret['errorMsg'] = 'Pas assez d\'or';
         echo json_encode($ret);
         exit;
     }
     SessionBusiness::getCookieSession()->getJoueur()->varTresor(-$pont->getPrix());
     SessionBusiness::getCookieSession()->getJoueur()->save();
     $pont->save();
     $ret['idPont'] = $pont->getId();
     $ret['montantTresor'] = SessionBusiness::getCookieSession()->getJoueur()->getTresor();
     echo json_encode($ret);
 }
 /**
  * Renvoie les Production liées à un Infrastructure
  * @param Infrastructure $infrastructure
  * @return ProductionCollection
  */
 public static function getByInfrastructure(Infrastructure $infrastructure)
 {
     $req = "SELECT * FROM production WHERE idInfrastructure = '" . $infrastructure->getIdInfrastructure() . "';";
     return DbHandler::collFromQuery($req, 'Production', 'ProductionCollection');
 }
Exemple #3
0
 /**
  * Crée un Infrastructure lié à ce Hexa
  * @return Infrastructure
  */
 public function createInfrastructure()
 {
     $infra = new Infrastructure();
     $infra->setIdHexa($this->getIdHexa());
     return $infra;
 }