Java Reference
In-Depth Information
Example 16−7: MudClient.java (continued)
// DESTROY: Destroy a named thing
else if (cmd.equals("destroy")) location.destroyThing(me, arg);
// OPEN: Create a new place and connect this place to it
// through the exit specified in the argument.
else if (cmd.equals("open")) {
if (arg.length() == 0)
throw new IllegalArgumentException("direction expected");
String name = getLine("What is the name of place there?: ");
String back = getLine("What is the direction from " +
"there back to here?: ");
String desc = getMultiLine("Please describe " +
name + ":");
location.createPlace(me, arg, back, name, desc);
}
// CLOSE: Close a named exit. Note: only closes an exit
// uni-directionally, and does not destroy a place.
else if (cmd.equals("close")) {
if (arg.length() == 0)
throw new IllegalArgumentException("direction expected");
location.close(me, arg);
}
// LINK: Create a new exit that connects to an existing place
// that may be in another MUD running on another host
else if (cmd.equals("link")) {
if (arg.length() == 0)
throw new IllegalArgumentException("direction expected");
String host = getLine("What host are you linking to?: ");
String mud =
getLine("What is the name of the MUD on that host?: ");
String place =
getLine("What is the place name in that MUD?: ");
location.linkTo(me, arg, host, mud, place);
System.out.println("Don't forget to make a link from " +
"there back to here!");
}
// DUMP: Save the state of this MUD into the named file,
// if the password is correct
else if (cmd.equals("dump")) {
if (arg.length() == 0)
throw new IllegalArgumentException("filename expected");
String password = getLine("Password: ");
location.getServer().dump(password, arg);
}
// QUIT: Quit the game
else if (cmd.equals("quit")) {
try { location.exit(me, myname + " has quit."); }
catch (Exception e) {}
System.out.println("Bye.");
System.out.flush();
System.exit(0);
}
// HELP: Print out a big help message
else if (cmd.equals("help")) System.out.println(help);
// Otherwise, this is an unrecognized command.
else System.out.println("Unknown command. Try 'help'.");
}
// Handle the many possible types of MudException
catch (MudException e) {
Search WWH ::




Custom Search