Global Positioning System Reference
In-Depth Information
a subclass. The same mechanisms can be used to extend the RemoteObject
interface to a RemotePlayer interface. The interface adds game-player to
the server-object communication. The RemotePlayer implementing class
RemotePlayerClient is private and can therefore not be extended.
The
connectivity information is hidden to the actual players.
To activate the players remote interface, the method can be overridden
in two ways:
protected RemoteObject getRemoteObject()
protected RemotePlayer getRemoteObject()
Whatever signature you decide on, the method should definitely be imple-
mented to create the RemotePlayerClient ; without it external clients will
only get a RemoteClient API. When using the first signature, the returned
object has to be cast to a player; alternatively, the casting should happen
inside the second method's signature. And, nally, to prevent renaming of
the super method to getRemotePlayer() , the label @Override will force the
compiler to fail, which is helpful for the developer to maintain an overview.
Adding client-server methods. Now, the client interface is in place and
the developer can add methods as needed in RemotePlayer and then in
LCPlayer . The general technique will be demonstrated with the first method
to init ialize the client player by passing a GameSet over the net.
First, the method signature has to be defined in the remote interface:
public interface RemotePlayer extends RemoteObject {
void init( GameSet gameSet ) throws RemoteException;
}
Then, the method is implemented in the inner class:
private class RemotePlayerClient
extends RemoteClient implements RemotePlayer
{
@Override // throws RemoteException
public void init( GameSet gameSet )
{
LCPlayer.this.init( gameSet );
}
}
to invoke the init method in the actual LCPlayer . Note that the methods
RemotePlayer.init and LCPlayer.init share the same signature for the de-
veloper's convenience; nevertheless, they are dierent methods in dierent
classes to the compiler.
Next, player.init(gameSet) is invoked from LondonChase.identify and
as listed in the server callback on page 174. Beware that this player refers
to the ServerPlayer object, which has to propagate the information to the
client.
 
Search WWH ::




Custom Search