Java Reference
In-Depth Information
Example 16−7: MudClient.java (continued)
if (e instanceof NoSuchThing)
System.out.println("There isn't any such thing here.");
else if (e instanceof NoSuchPerson)
System.out.println("There isn't anyone by that name here.");
else if (e instanceof NoSuchExit)
System.out.println("There isn't an exit in that direction.");
else if (e instanceof NoSuchPlace)
System.out.println("There isn't any such place.");
else if (e instanceof ExitAlreadyExists)
System.out.println("There is already an exit " +
"in that direction.");
else if (e instanceof PlaceAlreadyExists)
System.out.println("There is already a place " +
"with that name.");
else if (e instanceof LinkFailed)
System.out.println("That exit is not functioning.");
else if (e instanceof BadPassword)
System.out.println("Invalid password.");
else if (e instanceof NotThere) // Shouldn't happen
System.out.println("You can't do that when " +
"you're not there.");
else if (e instanceof AlreadyThere) // Shouldn't happen
System.out.println("You can't go there; " +
"you're already there.");
}
// Handle RMI exceptions
catch (RemoteException e) {
System.out.println("The MUD is having technical difficulties.");
System.out.println("Perhaps the server has crashed:");
System.out.println(e);
}
// Handle everything else that could go wrong.
catch (Exception e) {
System.out.println("Syntax or other error:");
System.out.println(e);
System.out.println("Try using the 'help' command.");
}
}
}
/**
* This convenience method is used in several places in the
* runMud() method above. It displays the name and description of
* the current place (including the name of the mud the place is in),
* and also displays the list of things, people, and exits in
* the current place.
**/
public static void look(RemoteMudPlace p)
throws RemoteException, MudException
{
String mudname = p.getServer().getMudName(); // Mud name
String placename = p.getPlaceName();
// Place name
String description = p.getDescription();
// Place description
Vector things = p.getThings();
// List of things here
Vector names = p.getNames();
// List of people here
Vector exits = p.getExits();
// List of exits from here
// Print it all out
Search WWH ::




Custom Search