<?phpclass state extends node{ public static $instance = null; public static function get_instance() { if(state::$instance === null) { if(empty($_POST['state'])) { state::$instance = new state(); } else { state::$instance = unserialize(base64_decode($_POST['state'])); } } return state::$instance; } public $m_player; public function __construct() { $player = new node('player'); $laboratory = new basic_room('laboratory'); $equipment = new basic_obj('equipment'); $lunch_room = new basic_room('lunch_room'); $wastebasket = new basic_obj('wastebasket'); $straw = new basic_obj('straw'); $machine = new basic_obj('machine'); $laboratory->m_north = $lunch_room; $laboratory->m_description = '<p>This is the laboratory. Equipment churns, bubbles, and steams. The door to the lunch room is north.</p>'; $equipment->m_description = 'The equipment does not matter, it merely provides ambiance.'; $equipment->m_takeable = false; $lunch_room->m_south = $laboratory; $lunch_room->m_description = '<p>An old vending machine hums in the corner next to a wastebasket. South is the lab.</p>'; $machine->m_description = '<p>The imposing machine is full of expired snack foods. They don\'t interest you.</p>'; $machine->m_takeable = false; $straw->m_description = 'A red and white striped drinking straw.'; $straw->m_takeable = true; $wastebasket->m_description = 'A wastebasket.'; $wastebasket->m_takeable = false; $wastebasket->move($straw); $lunch_room->move($machine); $lunch_room->move($wastebasket); $laboratory->move($equipment); $laboratory->move($player); $this->move($laboratory); $this->move($lunch_room); $this->m_player = $player; $this->m_player->m_parent->describe(); } public function local_obj($name) { return $this->m_player->m_parent->getr($name); } public function parse($i) { if($i == 'help' || $i == 'h' || $i == '?') { echo '<p>Help: Standard commands: l (look), n, s, e, w, x object (examine), t object (take)</p>'; } elseif($i == 'n' || $i == 'north') { $this->m_player->m_parent->north(); } elseif($i == 's' || $i == 'south') { $this->m_player->m_parent->south(); } elseif($i == 'e' || $i == 'east') { $this->m_player->m_parent->east(); } elseif($i == 'w' || $i == 'west') { $this->m_player->m_parent->east(); } elseif($i == 'l' || $i == 'look') { $this->m_player->m_parent->describe(); } elseif(preg_match('/^(x|examine)\s+([a-z]+)$/', $i, $m)) { $obj = $this->local_obj($m[2]); if($obj) { $obj->describe(); } else { echo '<p>It is not here.</p>'; } } elseif(preg_match('/^(t|take)\s+([a-z]+)$/', $i, $m)) { $obj = $this->local_obj($m[2]); if($obj) { $obj->take(); } else { echo '<p>It is not here.</p>'; } } else { echo '<p>I do not understand what you are trying to accomplish.</p>'; } echo "<pre>Debug:"; $this->dump(); echo '</pre>'; }}?>