vooga.network.gamelobby
Class VoogaLobbyClient

java.lang.Object
  extended by vooga.network.VoogaClient
      extended by vooga.network.gamelobby.VoogaLobbyClient
All Implemented Interfaces:
java.lang.Runnable

public class VoogaLobbyClient
extends VoogaClient

VoogaLobbyClient allows users to interact with lobbies on the server in the interest of playing networked games. It allows for joining/leaving and creating lobbies, and when a receiver is registered, it will notify the receiver of information coming from the server concerning the construction of new lobbies, users entering and exiting lobbies, and the starting of games.

Author:
tws10, tgr3, sam1

Constructor Summary
VoogaLobbyClient(java.lang.String userName, java.lang.String gameName)
          Creates a lobby client for the named user and game.
 
Method Summary
 void connect(java.net.InetAddress host)
          Connects to the server at the specified address.
 void createGameLobby(java.lang.String lobbyName, int occupancy)
          Creates a game lobby with the given name and occupancy.
protected  void initializeConnection()
          Performs any necessary set-up for a new connection.
 void joinGameLobby(long lobbyID)
          Joins the lobby identified by the given ID.
 void leaveGameLobby(long lobbyID)
          Leaves the lobby identified by the given ID.
 void registerReceiver(ILobbyInfoReceiver receiver)
          Registers a receiver for this client.
 void requestGameLobbies()
          Sends a request to the server asking to be notified of all existing lobbies and their occupants.
 void run()
           
 void startGame(long lobbyID)
          Starts the specified game with the users currently in the lobby.
 
Methods inherited from class vooga.network.VoogaClient
allowConnection, blockConnection, connect, connect, disconnect, getMyInputStream, getMyName, getMyOutputStream, getMySocket, isConnected, setConnected, setMyName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VoogaLobbyClient

public VoogaLobbyClient(java.lang.String userName,
                        java.lang.String gameName)
Creates a lobby client for the named user and game. The default receiver will print messages to Standard out.

Parameters:
userName -
gameName -
Method Detail

registerReceiver

public void registerReceiver(ILobbyInfoReceiver receiver)
Registers a receiver for this client. The receiver will be notified of any messages coming from the server.

Parameters:
receiver -

joinGameLobby

public void joinGameLobby(long lobbyID)
                   throws java.io.IOException
Joins the lobby identified by the given ID.

Parameters:
lobbyID -
Throws:
java.io.IOException

leaveGameLobby

public void leaveGameLobby(long lobbyID)
                    throws java.io.IOException
Leaves the lobby identified by the given ID.

Parameters:
lobbyID -
Throws:
java.io.IOException

createGameLobby

public void createGameLobby(java.lang.String lobbyName,
                            int occupancy)
                     throws java.io.IOException
Creates a game lobby with the given name and occupancy. An ID is automatically assigned and will be sent through notification. The creating user is automatically added to the lobby.

Parameters:
lobbyName -
occupancy - - the maximum players who can play the game.
Throws:
java.io.IOException

requestGameLobbies

public void requestGameLobbies()
                        throws java.io.IOException
Sends a request to the server asking to be notified of all existing lobbies and their occupants. This is conveyed through a call to the registered receiver.

Throws:
java.io.IOException

startGame

public void startGame(long lobbyID)
               throws java.io.IOException
Starts the specified game with the users currently in the lobby.

Parameters:
lobbyID -
Throws:
java.io.IOException

connect

public void connect(java.net.InetAddress host)
             throws java.io.IOException
Description copied from class: VoogaClient
Connects to the server at the specified address. The implementation of this method in each of the client subclasses should call the connect method with the given host and the port number specific to that client.

Specified by:
connect in class VoogaClient
Parameters:
host - The IP of an existing VoogaChatServer.
Throws:
java.io.IOException

initializeConnection

protected void initializeConnection()
Description copied from class: VoogaClient
Performs any necessary set-up for a new connection.

Specified by:
initializeConnection in class VoogaClient

run

public void run()