difficulty = $difficulty; } function getEncounterDifficulty() { return $this->difficulty; } function generate() { // A table of tables, indexed by [encounterLevel][encounter]. $table = array( 1 => array( "a bumblebee", "a butterfly", "an inchworm", "a sneaky snake", "a bunny", "a horsie" ), 2 => array( "Billy Idol", "a dire squirrel", "a hippy", "a licorice monster", "a creepy clown", "a 2nd level minion of the evil mastermind Xentar the Black" ), 3 => array( "a scawwy dwagon", "a balrog named Bill", "a vampire", "Jolly R. Blackburn", "an undead creepy clown", "The evil mastermind Xentar the Black himself" ) ); $result = ""; // 3-in-6 chance of an encounter if( d6() <= 3 ) { // If the table has in index set for the desired encounter difficulty, // pick a random encounter from the appropriate subtable. Otherwise // set an error message. if( isset($table[$this->difficulty]) ) $result = $table[$this->difficulty][mt_rand(0,count($table[$this->difficulty])-1)]; else $result = "(Encounter of level $this->difficulty not supported by MyNewEncounter.)"; } if( $result != "" ) $result = "Encounter: $result"; $this->text = $result; } function getText() { // This function returns the last result produced by generate(). return $this->text; } } ?>