package mug12; /** * A place in the world of Grinnell. Places hold objects and * people and are also connected to other places. * * @author CSC152 2004F */ import java.util.Hashtable; import java.util.Vector; public class PlaceObject implements Place { //Fields String name; String description; Vector adjacent; Vector stuffInRoom; Vector personsInRoom; Hashtable verbs; //constructors public PlaceObject(String _name, String _description, Vector _adjacent, Vector _stuffInRoom, Vector _personsInRoom, Hashtable _verbs) { this.name = _name; this.description = _description; this.adjacent = _adjacent; this.stuffInRoom = _stuffInRoom; this.personsInRoom = _personsInRoom; this.verbs = _verbs; }//Place() /** * Get the name of this thing. Every thing is supposed to have a * unique name. */ public String getName() { return this.name; }//getName() /** * Get a description of the object, which can then be presented * to the user. */ public String describe() { return this.description; }//describe() /** *finds the verbs that can be performed on said object */ public Hashtable verbs() { return this.verbs; }//verbs() /** *finds the stuff needed to run a verb *returns a -1 if the verb doesn't exist for this object *returns a 0 if the verb does exist but does not change anything *returns a 1 if the verb exists and changes things */ public Integer checkVerb(String verb) { if (this.verbs.get(verb).equals(null)) return new Integer(-1); else { Integer returned = (Integer) this.verbs.get(verb); return returned; } }//checkVerb(String) /** * Is this room available to person p? */ public boolean available(Person p) { return true; //special stuff for room with special access }//available(Person) /** * Find out what people are in the place. */ public String[] persons() { String[] stuff = new String[this.personsInRoom.size()]; this.personsInRoom.copyInto(stuff); return stuff; }//persons() /** * Find out what things are in the place. */ public String[] things() { String[] stuff = new String[this.stuffInRoom.size()]; this.stuffInRoom.copyInto(stuff); return stuff; }//things() /** * Determine the neighboring places. */ public String[] neighbors() { String[] stuff = new String[this.adjacent.size()]; this.adjacent.copyInto(stuff); return stuff; }//neighbors() public void addPerson(String name) { this.personsInRoom.add(name); }//addPerson(String) public void removePerson(String name) { this.personsInRoom.remove(name); }//removePerson(String) public void addThing(String name) { this.stuffInRoom.add(name); }//addThing(String) public void removeThing(String name) { this.stuffInRoom.remove(name); }//removeThing(String) } // interface Place