set_model($model);
$this->set_color($color);
$this->set_os($os);
$this->set_image($image);
$this->set_size($size);
$this->set_laws($laws);
}
public function __toString()
{
$string = '
Your ' . $this->get_size() . ' sized ' . $this->get_color() . ' ' . $this->get_model() . ' running ' . $this->get_os() . ' will be built shortly. Thank you.
';
$laws = $this->get_laws();
if (!empty($laws)) {
$string .= '
Your robot will obey the following laws:
';
for ($i = 0; $i < count($laws); $i++) {
$l = '';
switch ($i) {
case 0:
$l = 'First';
break;
case 1:
$l = 'Second';
break;
case 2:
$l = 'Third';
break;
}
$string .= '- ' . $l . ' Law:' . $laws[$i] . '
';
}
$string .= '
';
} else {
$string .= 'Your robot has no rules.
';
}
$string .= '
';
return $string;
}
public function get_model()
{
return $this->model;
}
public function set_model($model)
{
$this->model = $model;
}
public function get_color()
{
return $this->color;
}
public function set_color($color)
{
$this->color = $color;
}
public function get_os()
{
return $this->os;
}
public function set_os($os)
{
$this->os = $os;
}
public function get_image()
{
return $this->image;
}
public function set_image($image)
{
$this->image = $image;
}
public function get_size()
{
return $this->size;
}
public function set_size($size)
{
$this->size = $size;
}
public function get_laws()
{
return $this->laws;
}
public function set_laws($laws)
{
$this->laws = $laws;
}
}
$models = [
'Sonny' => 'img/sonny.jpg',
'Rosey' => 'img/rosey.jpeg',
'SICO' => 'img/sico.jpeg',
'Data' => 'img/data.jpeg',
'Gort' => 'img/gort.png',
'Wall-E' => 'img/walle.png',
'Optimus Prime' => 'img/optimus.png',
'Hal 9000' => 'img/hal.png',
'Twiki' => 'img/twiki.jpg',
'Bender' => 'img/bender.png',
'Johnny 5' => 'img/johnny.png',
];
?>
Robot
I, Object
'A robot may not injure a human being or, through inaction, allow a human being to come to harm.',
'second' => 'A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.',
'third' => 'A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.',
];
$form = '
';
return $form;
}
function message($models)
{
if (isset($_POST['model']) && isset($_POST['color']) && isset($_POST['os']) & isset($_POST['size']))
$robot = new Robot($_POST['model'], $_POST['color'], $_POST['os'], $models[$_POST['model']], $_POST['size'], isset($_POST['laws']) ? $_POST['laws'] : '');
if (!$robot)
return form();
ob_start();
print_r($robot);
$dump = ob_get_clean();
$msg = '
Processing...
' . $robot->__toString() . '
';
$msg .= $dump;
$msg .= '
';
return $msg;
}
?>