Java Reference
In-Depth Information
Example 16−7: MudClient.java (continued)
System.out.println(e);
System.out.println("Usage: java MudClient <host> <mud> [<place>]");
System.exit(1);
}
}
/**
* This method is the main loop of the MudClient. It places the person
* into the place (using the enter() method of RemoteMudPlace). Then it
* calls the look() method to describe the place to the user, and enters a
* command loop to prompt the user for a command and process the command
**/
public static void runMud(RemoteMudPlace entrance, MudPerson me)
throws RemoteException
{
RemoteMudPlace location = entrance; // The current place
String myname = me.getName();
// The person's name
String placename = null;
// The name of the current place
String mudname = null;
// The name of the mud of that place
try {
// Enter the MUD
location.enter(me, myname, myname + " has entered the MUD.");
// Figure out where we are (for the prompt)
mudname = location.getServer().getMudName();
placename = location.getPlaceName();
// Describe the place to the user
look(location);
}
catch (Exception e) {
System.out.println(e);
System.exit(1);
}
// Now that we've entered the MUD, begin a command loop to process
// the user's commands. Note that there is a huge block of catch
// statements at the bottom of the loop to handle all the things that
// could go wrong each time through the loop.
for(;;) { // Loop until the user types "quit"
try { // Catch any exceptions that occur in the loop
// Pause just a bit before printing the prompt, to give output
// generated indirectly by the last command a chance to appear.
try { Thread.sleep(200); } catch (InterruptedException e) {}
// Display a prompt, and get the user's input
String line = getLine(mudname + '.' + placename + "> ");
// Break the input into a command and an argument that consists
// of the rest of the line. Convert the command to lowercase.
String cmd, arg;
int i = line.indexOf(' ');
if (i == -1) { cmd = line; arg = null; }
else {
cmd = line.substring(0, i).toLowerCase();
arg = line.substring(i+1);
}
if (arg == null) arg = "";
Search WWH ::




Custom Search