Пример #1
0
 /**
  * @param Hexa $hexa1
  * @param Hexa $hexa2
  * @return Infrastructure
  */
 public static function getByHexas(Hexa $hexa1, Hexa $hexa2)
 {
     $index = min($hexa1->getId(), $hexa2->getId()) . '_' . max($hexa1->getId(), $hexa2->getId());
     if (isset(self::$indexByHexas[$index])) {
         return self::$indexByHexas[$index];
     } else {
         $infra = InfrastructureBusiness::getPontEntre2Hexas($hexa1, $hexa2);
         if (is_null($infra)) {
             self::$indexByHexas[$index] = null;
         } else {
             self::store($infra);
         }
         return $infra;
     }
 }
Пример #2
0
 /**
  * Génère le JSON pour les infrastructures
  * @return string
  */
 public function getInfrastructures()
 {
     $infras = InfrastructureBusiness::getFromHexas($this->getHexas());
     return ',"infrastructures":' . $infras->getJSon();
 }
Пример #3
0
 function supprimerPont()
 {
     $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();
     $riviere = $hexa->riviereCote($_POST['angle']);
     if (is_null($riviere)) {
         $ret['error'] = 3;
         $ret['errorMsg'] = 'Rivière inexistante sur ce côté de la case';
         echo json_encode($ret);
         exit;
     }
     $pont = InfrastructureBusiness::getPontEntre2Hexas($riviere->getHexa1(), $riviere->getHexa2());
     if (is_null($pont)) {
         $ret['error'] = 4;
         $ret['errorMsg'] = 'Pont inexistant';
         echo json_encode($ret);
         exit;
     }
     if (!$pont->destructiblePar(SessionBusiness::getCookieSession()->getJoueur())) {
         $ret['error'] = 5;
         $ret['errorMsg'] = 'Ce pont n\'est pas destructible par ce joueur';
         echo json_encode($ret);
         exit;
     }
     $ret['idPont'] = $pont->getId();
     if ($pont->getEnConstruction() == -1) {
         if (SessionBusiness::getCookieSession()->getJoueur()->getTresor() < $pont->getPrix()) {
             $ret['error'] = 6;
             $ret['errorMsg'] = 'Pas assez d\'or';
             echo json_encode($ret);
             exit;
         }
         $pont->setEnConstruction(0);
         $pont->save();
         SessionBusiness::getCookieSession()->getJoueur()->varTresor(-$pont->getPrix());
         SessionBusiness::getCookieSession()->getJoueur()->save();
     } elseif ($pont->getEnConstruction() == 1) {
         $pont->delete();
         SessionBusiness::getCookieSession()->getJoueur()->varTresor($pont->getPrix());
         SessionBusiness::getCookieSession()->getJoueur()->save();
     } elseif ($pont->getEnConstruction() == 0) {
         $pont->setEnConstruction(-1);
         $pont->save();
     }
     $ret['montantTresor'] = SessionBusiness::getCookieSession()->getJoueur()->getTresor();
     echo json_encode($ret);
 }
Пример #4
0
 /**
  * @return void
  */
 public function delete()
 {
     InfrastructureBusiness::delete($this);
 }
Пример #5
0
 /**
  * Renvoie les Infrastructures liés à l'objet
  * @return InfrastructureCollection
  */
 public function getInfrastructures()
 {
     if (is_null($this->cacheInfrastructures)) {
         $this->cacheInfrastructures = InfrastructureBusiness::getByHexa($this);
         $this->cacheInfrastructures->store();
     }
     return $this->cacheInfrastructures;
 }