Exemplo n.º 1
0
 /**
  * calculates the hourly production of all production buildings in a particular city.
  * production = (level of building * number of workers in the building) % health of building
  *
  * @param City $city
  * @return array
  */
 public static function calculateProduction(City $city)
 {
     $production = ['food' => 0, 'iron' => 0, 'lumber' => 0, 'stone' => 0];
     foreach ($city->workingBuildings() as $building) {
         $profit = number_format($building->level * $building->workers * ($building->health / 100), 2);
         switch ($building->type) {
             case 1:
                 $production['food'] += $profit;
                 break;
             case 2:
                 $production['stone'] += $profit;
                 break;
             case 3:
                 $production['iron'] += $profit;
                 break;
             case 4:
                 $production['lumber'] += $profit;
                 break;
         }
     }
     return $production;
 }