示例#1
0
 public function goToHome(Vehicle $vehicle)
 {
     while ($this->currentPosition != $this->brain->locate($vehicle)) {
         if (is_null($this->currentForwardLeg)) {
             $this->rightLeg->moveForward();
             $this->currentForwardLeg = $this->rightLeg;
             $this->currentPosition++;
             break;
         } elseif ($this->currentForwardLeg === $this->rightLeg) {
             $this->leftLeg->moveForward();
             $this->currentForwardLeg = $this->leftLeg;
             $this->currentPosition++;
             break;
         } else {
             $this->rightLeg->moveForward();
             $this->currentForwardLeg = $this->rightLeg;
             $this->currentPosition++;
             break;
         }
     }
     //Now we can get in to the vehicle
     if ($vehicle instanceof VehicleWithDoor) {
         $vehicle->openDoor();
     }
     //This is supposedly takes us in the vehicle
     //We already know the $this->currentForwardLeg is not null
     if ($this->currentForwardLeg === $this->rightLeg) {
         $this->leftLeg->moveForward();
         $this->currentForwardLeg = $this->leftLeg;
         $this->currentPosition++;
     } else {
         $this->rightLeg->moveForward();
         $this->currentForwardLeg = $this->rightLeg;
         $this->currentPosition++;
     }
     if ($vehicle instanceof VehicleWithDoor) {
         $vehicle->closeDoor();
     }
     $vehicle->driveTo(HOME_POSITION, function (Vehicle $vehicle, $position) {
         $this->currentPosition = $position;
         //Now we can get in to the vehicle
         if ($vehicle instanceof VehicleWithDoor) {
             $vehicle->openDoor();
         }
         //Go out of the vehicle
         if ($this->currentForwardLeg === $this->rightLeg) {
             $this->leftLeg->moveForward();
             $this->currentForwardLeg = $this->leftLeg;
             $this->currentPosition++;
         } else {
             $this->rightLeg->moveForward();
             $this->currentForwardLeg = $this->rightLeg;
             $this->currentPosition++;
         }
     });
 }
示例#2
0
 /**
  * @param Leg $other
  * @return bool
  */
 public function sameValueAs(Leg $other)
 {
     if ($this->loadLocation() !== $other->loadLocation()) {
         return false;
     }
     if ($this->unloadLocation() !== $other->unloadLocation()) {
         return false;
     }
     if ($this->loadTime() != $other->loadTime()) {
         return false;
     }
     if ($this->unloadTime() != $other->unloadTime()) {
         return false;
     }
     return true;
 }