Exemple #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.";
         }
     }
 }
Exemple #2
0
<!DOCTYPE html>
<html lang="en">
	<head>
	    <meta charset="utf-8">  
	    <title>The Journal.ie</title>
	    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
	</head>
	<body class="bg-primary">
		<div class="container">
			<?php 
require_once 'classes/River.php';
$url_parts = preg_split('/\\//', $_SERVER['REQUEST_URI'], NULL, PREG_SPLIT_NO_EMPTY);
$last_part_of_url = end($url_parts);
$success = River::printRiver($last_part_of_url);
if (FALSE === $success) {
    echo 'Too many requests. If this page does not refresh automatically in 5 seconds please refresh your browser...';
    echo '<meta http-equiv="refresh" content="5">';
}
?>
		</div>
	</body>
</html>