package project; import java.util.Comparator; import java.io.BufferedReader; import java.io.InputStreamReader; import rebelsky.io.Pen; import java.util.Hashtable; public class WorldBuilderInterface { /// +--------+-------------------------------------------------- // | Fields | // +--------+/ String roomname; String thingname; String description; String attribute; String verb; String object; Person per; Place pla; Thing thi; String[] location = { "Harris ", "ARH ", "Noyce ", "Burling ", "Bucksbaum ", "the Forum Grill ", "Carnegie ", "the bookstore ", "the post office ", "Steiner ", "Goodnow ", "Burling 4th ", "Central Campus ", "the PEC ", "my room on East Campus ", "my room on South Campus ", "my room on North Campus ", "the football field ", "the soccer field ", "Mac Field ", "the tennis courts ", "the CDO ", "admissions ", "the Zircle ", "Quad Dining Hall ", "Cowles Dining Hall " }; Pen pen; BufferedReader keyboard; /* Hashtable hashrooms; Hashtable hashobjects; */ // +----------------+------------------------------------------ // | Constructors| // +----------------+ public WorldBuilderInterface() { this.pen = new Pen(); this.keyboard = new BufferedReader(new InputStreamReader(System.in)); } // ReadAndParse(WorldInterface) // +----------------+------------------------------------------ // | Public Methods | // +----------------+ public void initialize() throws Exception { pen.print("Welcome to the World Builder Program. Please type help for a list of commands. "); pen.flush(); String input = keyboard.readLine(); String[] array1 = input.split(" "); String initial = array1[0]; if (initial.equals("help")) { pen.println("You may "); pen.println("P - list all the places in the world"); pen.println("p PLACE - list all the people in one place"); pen.println("t PLACE - list all the things in a place"); pen.println("m NAME - modify something"); pen.println("c - create something"); pen.println("a - list all valid attributes"); pen.println("q - quit"); pen.print("What would you like to do? "); pen.flush(); String command = keyboard.readLine(); if (array1.length >= 2) { this.object = array1[1]; } parseWorld(command, this.object); } else { initialize(); } } // initialize() public void parseWorld(String command, String object) throws Exception { this.object = object; if (command.equals("q")) { pen.println("Goodbye"); } else { if (command.equals("P")) { printStuff(this.location); } if (command.equals("p")){ pen.println("people"); //printStuff(pla.persons()); } if (command.equals("t")){ pen.println("things"); //printStuff(pla.things()); } if (command.equals("m")){ pen.print("What would you like to modify? "); pen.flush(); String item = keyboard.readLine(); pen.print("Please enter an attribute for " + item + ": "); pen.flush(); String newattri = keyboard.readLine(); // store the attribute; } if (command.equals("c")) { pen.print("Please enter a name for the new object: "); pen.flush(); String name = keyboard.readLine(); pen.print("Please describe " + name + ": "); pen.flush(); String descrip = keyboard.readLine(); attribute(name); pen.print("Where does " + name + " go? "); String destination = keyboard.readLine(); // store the thing in the appropriate place } pen.print("What would you like to do next? "); pen.flush(); String nextReply = keyboard.readLine(); String[] arrayOfInput = nextReply.split(" "); String newcommand = arrayOfInput[0]; if (arrayOfInput.length >= 2) { this.object = arrayOfInput[1]; } parseWorld(newcommand, this.object); } } // parseWorld(String, String) public void attribute(String creation) throws Exception { pen.print("Please enter an attribute: "); pen.flush(); String attribute = keyboard.readLine(); pen.print("Is " + attribute + " a numeric or string attribute? "); pen.flush(); String response = keyboard.readLine(); if (response.equals("numeric")) { pen.print("Please enter a string value for " + attribute + ": "); pen.flush(); String strattribute = keyboard.readLine(); // store response and strattribute } else { pen.print("Please enter a numeric value for " + attribute + ": "); pen.flush(); String numattribute = keyboard.readLine(); // store response and numattribute } pen.print("Does " + creation + " have other attributes? [y/n]: "); pen.flush(); String answer = keyboard.readLine(); if ((answer.equals("y")) || (answer.equals("Y"))) attribute(creation); } // attribute() public void printStuff(String[] array) throws Exception { for (int i = 0; i < array.length; i++) { pen.println(array[i]); } } // printStuff() } // class WorldBuilderInterface