Example #1
0
 public function crossing()
 {
     River::LogHeader();
     // by inserting header delete all previous info in log file
     if (Config::getChildren() == 1) {
         echo "Not enough children to cross the river. Are you sure you took all your kids from home?";
     } else {
         if (Config::getChildren() == 0) {
             if (Config::getAdults() == 0) {
                 echo "I guess all are staying at home, nobody wanted to move to the other bank, yep?";
             } else {
                 echo "Not enough children to cross the river. Are you sure you took all your kids from home?";
             }
         } else {
             if (Config::getAdults() > 0) {
                 for ($i = 0; $i < Config::getAdults(); $i++) {
                     $this->move++;
                     $this->transfer($this->move);
                     Child::twoChildrenMove();
                     $this->move++;
                     $this->transfer($this->move);
                     Child::childBack();
                     $this->move++;
                     $this->transfer($this->move);
                     Adult::move();
                     $this->move++;
                     $this->transfer($this->move);
                     Child::childBack();
                 }
             }
             if (Config::getChildren() > 2) {
                 for ($i = 0; $i < Config::getChildren() - 2; $i++) {
                     $this->move++;
                     $this->transfer($this->move);
                     Child::childMove();
                     $this->move++;
                     $this->transfer($this->move);
                     Child::childBack();
                 }
             }
             // move boatOwner - goes in any case
             $this->move++;
             $this->transfer($this->move);
             Child::twoChildrenMove();
             $this->move++;
             $this->transfer($this->move);
             Child::ChildBack();
             $this->move++;
             $this->transfer($this->move);
             Fisherman::move();
             $this->move++;
             $this->transfer($this->move);
             Child::childBack();
             //finally move 2 last children to right bank - goes in any case
             $this->move++;
             $this->transfer($this->move);
             Child::twoChildrenMove();
             echo "they will have to cross the river " . $this->move . " times.";
         }
     }
 }