Created
July 29, 2017 15:19
-
-
Save ryantxr/871374e620dfbf04a8cda93c5e1a98a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Adventurer { | |
public $class; | |
public $name; | |
public $inventory = []; | |
public $handler; | |
function __construct($name, $class, $handler=null) { | |
$this->class = $class; | |
$this->name = $name; | |
$this->handler = $handler; | |
} | |
function out() { | |
echo "**********\n"; | |
echo "Name: " . $this->name . "\n"; | |
echo "Class: " . $this->class . "\n"; | |
if ( $this->handler && ! $this->handler->daytime) { | |
echo "Sleeping ...\n"; | |
} | |
else { | |
echo "Awake ...\n"; | |
} | |
echo implode("\n", $this->inventory) . "\n"; | |
} | |
} | |
// print_r($a); | |
class AdventurerHandler { | |
public $adventurers = []; | |
public $daytime = true; | |
function process() { | |
foreach ($this->adventurers as $adventurer) { | |
$adventurer->out(); | |
} | |
} | |
function addAdventurer($name, $class) { | |
$this->adventurers[] = new Adventurer($name, $class, $this); | |
} | |
} | |
$handler = new AdventurerHandler; | |
$handler->addAdventurer('Fred', 'Warrior'); | |
$handler->addAdventurer('Jake', 'Human'); | |
$handler->addAdventurer('Sally', 'Priest'); | |
$handler->addAdventurer('Steve', 'Ogre'); | |
$handler->addAdventurer('June', 'Orc'); | |
$handler->addAdventurer('April', 'Human'); | |
$handler->addAdventurer('Joli', 'Human'); | |
$handler->addAdventurer('Archie', 'Human'); | |
$handler->addAdventurer('Wen', 'Human'); | |
$handler->addAdventurer('Eunbank', 'Human'); | |
$handler->process(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment