diff --git a/chargen.php b/chargen.php index aba05c2..06c3822 100644 --- a/chargen.php +++ b/chargen.php @@ -5,5 +5,4 @@ $person = new Character(); $this_person = new View($person); -print("Your new crew: {$this_person}\n"); -?> +print $this_person; diff --git a/lib/character.php b/lib/character.php index cae9a41..b4c8b76 100644 --- a/lib/character.php +++ b/lib/character.php @@ -8,16 +8,16 @@ public function __construct($data = array()) { $this->upp_s = $this->upp_to_s($this->upp); } - public function to_s() { - $upp_s = $this->upp_to_s($this->upp); - print("$this->name [$this->gender] $upp_s \n"); + public function __toString() { + $return_string = "{$this->name} [{$this->gender}] {$this->upp_s}"; + return $return_string; } private function set_gender() { return rand(0,1) ? "F" : "M"; } private function upp_to_s(array $upp) { - $string = ''; + $string = ''; foreach ($upp as $s) { $string .= dechex($s); } @@ -74,5 +74,3 @@ private function go_to_the_gym(array $upp) { } } -?> - diff --git a/lib/view.php b/lib/view.php index c8a92b2..fd6d3f5 100644 --- a/lib/view.php +++ b/lib/view.php @@ -1,15 +1,14 @@ name = $person->name; - $this->gender = $person->gender; - $this->upp_s = $person->upp_s; + protected $person; + + public function __construct(Character $person) { + $this->person = $person; } + public function __toString() { - $return_string = "$this->name [$this->gender] $this->upp_s"; + $return_string = "Your new crew: {$this->person}\n"; return $return_string; } } -?> -