Beispiel #1
0
 /**
  * Renvoie la liste des batiments qu'il est possible de construire dans la ville
  * @return BatimentCollection
  */
 public function listeBatimentsAConstruire()
 {
     $ret = new BatimentCollection();
     $typesAConstruire = array();
     $nePasConstruire = array();
     foreach (Batiments::$couts as $idType => $bat) {
         $trouve = false;
         foreach ($this->getBatiments() as $batiment) {
             /** @var Batiment $batiment */
             if ($batiment->getIdType() == $idType) {
                 if (!$bat['niveaux']) {
                     continue 2;
                 }
                 if ($batiment->getEnConstruction() == '1' || $batiment->getEnConstruction() == '-1') {
                     $nePasConstruire[] = $idType;
                 } else {
                     $typesAConstruire[$idType] = array($idType, $batiment->getNiveau() + 1);
                 }
                 $trouve = true;
             }
         }
         if (!$trouve) {
             $typesAConstruire[$idType] = array($idType, 1);
         }
     }
     foreach ($nePasConstruire as $idType) {
         if (isset($typesAConstruire[$idType])) {
             unset($typesAConstruire[$idType]);
         }
     }
     foreach ($typesAConstruire as $idType => $bat) {
         $new = $this->createBatiment();
         $new->setIdType($idType);
         $new->setNiveau($bat[1]);
         $ret->ajout($new);
     }
     return $ret;
 }