Room newRoom = null;
boolean noWay = false;
switch(cmd) {
case Cmd.UNKNOWN:
println("Unknown command!");
break;
case Cmd.NORTH:
if (room.north != null) {
newRoom = room.north;
} else
noWay = true;
break;
case Cmd.EAST:
if (room.east != null) {
newRoom = room.east;
} else
noWay = true;
break;
case Cmd.SOUTH:
if (room.south != null) {
newRoom = room.south;
} else
noWay = true;
break;
case Cmd.WEST:
if (room.west != null) {
newRoom = room.west;
} else
noWay = true;
break;
case Cmd.HELP:
println("Sorry, help not written yet. I cannot help it");
break;
default:
println("LOGIC ERROR: Unhandled case " + (char)cmd);
break;
}
if (noWay) {
println("I see no way to go in that direction");
return;
}
if (newRoom != null) {
if (room.exitMessage != null) {
println(room.exitMessage);
}
// The magic happens: we change rooms.
room = newRoom;
println(room.entryMessage);
}