Esempio n. 1
0
 /**
  * @param BuildingRepair $buildingRepair
  * @param int $time
  */
 public function repair(BuildingRepair $buildingRepair, $time = 60)
 {
     $building = $buildingRepair->getBuilding();
     $currentCondition = $building->getCurrentCondition();
     $startedCondition = $buildingRepair->getStartedCondition();
     $type = $buildingRepair->getType();
     $timeConstant = $this->buildingRepairPrice->getTimeConstant($type);
     $updateTimes = $timeConstant * (100 - $startedCondition) / $time;
     $step = (100 - $startedCondition) / $updateTimes;
     $building->setCurrentCondition($currentCondition + $step);
     $this->buildingRepository->update();
 }
Esempio n. 2
0
 function it_should_repair_building(BuildingRepository $buildingRepository, BuildingRepair $buildingRepair, Building $building, BuildingRepairPrice $buildingRepairPrice)
 {
     $time = 60;
     $type = BuildingRepair::TYPE_VERY_FAST_ID;
     $timeConstant = BuildingRepair::TYPE_VERY_FAST_TIME_CONSTANT;
     $startedCondition = 10;
     $currentCondition = 20;
     $buildingRepair->getBuilding()->willReturn($building);
     $building->getCurrentCondition()->willReturn($currentCondition);
     $buildingRepair->getType()->willReturn($type);
     $buildingRepair->getStartedCondition()->willReturn($startedCondition);
     $buildingRepairPrice->getTimeConstant($type)->willReturn($timeConstant);
     $updateTimes = BuildingRepair::TYPE_VERY_FAST_TIME_CONSTANT * (100 - $startedCondition) / $time;
     $step = (100 - $startedCondition) / $updateTimes;
     $building->setCurrentCondition($currentCondition + $step)->shouldBeCalled();
     $buildingRepository->update()->shouldBeCalled();
     $this->repair($buildingRepair, $time);
 }