Java Reference
In-Depth Information
Example 16−7: MudClient.java (continued)
"End with a '.' on a line by itself.\n" +
"Or enter a '<<' followed by a filename");
// Make the prompt and instructions appear now.
System.out.flush();
// Read lines
String line;
while((line = br.readLine()) != null) { // Until EOF
if (line.equals(".")) break; // Or until a dot by itself
// Or, if a file is specified, start reading from it
// instead of from the console.
if (line.trim().startsWith("<<")) {
String filename = line.trim().substring(2).trim();
br = new BufferedReader(new FileReader(filename));
continue; // Don't count the << as part of the input
}
// Add the line to the collected input
else text += line + "\n";
}
// If we got at least one line, return it. Otherwise, chastise
// the user and go back to the prompt and the instructions.
if (text.length() > 0) return text;
else System.out.println("Please enter at least one line.");
}
// If there were errors, for example an IO error reading a file,
// display the error and loop again, displaying prompt and
// instructions
catch(Exception e) { System.out.println(e); }
}
}
/** This is the usage string that explains the available commands */
static final String help =
"Commands are:\n" +
"look: Look around\n" +
"examine <thing>: examine the named thing in more detail\n" +
"describe <person>: describe the named person\n" +
"go <direction>: go in the named direction (i.e. a named exit)\n" +
"say <message>: say something to everyone\n" +
"do <message>: tell everyone that you are doing something\n" +
"talk <person>: talk to one person. Will prompt for message\n" +
"change: change how you are described. Will prompt for input\n" +
"create <thing>: create a new thing. Prompts for description \n" +
"destroy <thing>: destroy a thing.\n" +
"open <direction>: create an adjoining place. Prompts for input\n"+
"close <direction>: close an exit from this place.\n" +
"link <direction>: create an exit to an existing place,\n" +
" perhaps on another server. Will prompt for input.\n" +
"dump <filename>: save server state. Prompts for password\n" +
"quit: leave the Mud\n" +
"help: display this message";
}
Search WWH ::




Custom Search