feud.testgame
Class BlueThunderClient

java.lang.Object
  extended byfeud.testgame.BlueThunderClient
All Implemented Interfaces:
ClientPreProcessor, DataTransferListener, GameClient

public class BlueThunderClient
extends java.lang.Object
implements DataTransferListener, ClientPreProcessor, GameClient

The client, i.e. the actual game. This client also opens a window with a simple server browser to join an existing server or start a new one.


Constructor Summary
BlueThunderClient()
          Create a new client.
 
Method Summary
 void afterReceiving()
          This is called after receiving the response from the server.
 void beforeReceiving()
          This is called after sending and before receiving the response from the server.
 void beforeSending()
          This method will be called before sending data.
 void connect(ServerEntry server, java.lang.String name)
          Connect the client to a server
 DataContainer[] dataReceived(DataContainer c, int type)
          Data has been received by the server/client to which this listener has been added.
 void dataReceivedEnd()
          The server/client has finished receiving in this transfer.
 void disconnect()
          Disconnect from the current server
 ServerEntry getServer()
          Returns the server represented by a server entry.
 boolean isConnected()
          Checks if the client is connected to a server.
 void quit()
          Shuts down the client and everything...
 boolean runsServer()
          Returns true, is a local server is running on this client machine.
 void shutDownServer()
          Shuts down a local server on the client machine if one is running.
 void startServer(int port)
          Starts a local server on the client machine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlueThunderClient

public BlueThunderClient()
                  throws java.lang.Exception
Create a new client. This starts the client and enters the game loop.

Throws:
java.lang.Exception
Method Detail

connect

public void connect(ServerEntry server,
                    java.lang.String name)
             throws java.lang.Exception
Description copied from interface: GameClient
Connect the client to a server

Specified by:
connect in interface GameClient
Parameters:
server - ServerEntry the server entry of the server to connect to
name - String the name of this client
Throws:
java.lang.Exception

disconnect

public void disconnect()
                throws java.lang.Exception
Description copied from interface: GameClient
Disconnect from the current server

Specified by:
disconnect in interface GameClient
Throws:
java.lang.Exception

isConnected

public boolean isConnected()
Description copied from interface: GameClient
Checks if the client is connected to a server.

Specified by:
isConnected in interface GameClient
Returns:
boolean is it connected or not?

getServer

public ServerEntry getServer()
Description copied from interface: GameClient
Returns the server represented by a server entry.

Specified by:
getServer in interface GameClient
Returns:
ServerEntry the server

startServer

public void startServer(int port)
                 throws java.lang.Exception
Description copied from interface: GameClient
Starts a local server on the client machine.

Specified by:
startServer in interface GameClient
Parameters:
port - int the port on which the server should listen
Throws:
java.lang.Exception

shutDownServer

public void shutDownServer()
                    throws java.lang.Exception
Description copied from interface: GameClient
Shuts down a local server on the client machine if one is running.

Specified by:
shutDownServer in interface GameClient
Throws:
java.lang.Exception

runsServer

public boolean runsServer()
Description copied from interface: GameClient
Returns true, is a local server is running on this client machine.

Specified by:
runsServer in interface GameClient
Returns:
boolean is it?

quit

public void quit()
Description copied from interface: GameClient
Shuts down the client and everything...

Specified by:
quit in interface GameClient

beforeSending

public void beforeSending()
Description copied from interface: ClientPreProcessor
This method will be called before sending data. It is usually the place, where the actual client implementation prepares/sets the data for the client to send in the coming transfer attempt.

Specified by:
beforeSending in interface ClientPreProcessor

beforeReceiving

public void beforeReceiving()
Description copied from interface: ClientPreProcessor
This is called after sending and before receiving the response from the server. It's totally up to the implementation what (if anything) to do here.

Specified by:
beforeReceiving in interface ClientPreProcessor

afterReceiving

public void afterReceiving()
Description copied from interface: ClientPreProcessor
This is called after receiving the response from the server. It's totally up to the implementation what (if anything) to do here.

Specified by:
afterReceiving in interface ClientPreProcessor

dataReceivedEnd

public void dataReceivedEnd()
Description copied from interface: DataTransferListener
The server/client has finished receiving in this transfer. This method will be called once after receiving all data, while the one above can be called multiple times while receiving.

Specified by:
dataReceivedEnd in interface DataTransferListener

dataReceived

public DataContainer[] dataReceived(DataContainer c,
                                    int type)
Description copied from interface: DataTransferListener
Data has been received by the server/client to which this listener has been added. This method will be called for each DataContainer. A transfer can consist of many DataContainers.

Specified by:
dataReceived in interface DataTransferListener
Parameters:
c - the DataContainer that has been received.
type - the type of the message like MessageType defines it
Returns:
DataContainer[] an optional result. The client doesn't care for this result. The server will send it back to the client from which is has received the data.