org.globalse.arena.frag.game
Class GameManager

java.lang.Object
  |
  +--org.globalse.arena.frag.game.GameManager

public class GameManager
extends java.lang.Object
implements EventSource, EventSink

The GameManager class handles the creation and joining of games. It provides the interface for interaction with the underlying layer (Network components or ARENA itself). The actual work of creating a game with objects etc. is delegated to a subclass of GameSetup. A GameManager creates three event dispatcher classes: a remote dispatcher that relays events to all other peers, a local dispatcher that relays events to the GameManager and the ObjectManager and a general dispatcher that relays events to both the local and the remote dispatcher. $Id: GameManager.html,v 1.1 2003/02/12 18:06:19 schoecke Exp $


Constructor Summary
GameManager(java.lang.String gameName, java.lang.String playerName)
          The constructor to create a instance of the GameManager.
 
Method Summary
 EventDistributor eventDistributor()
          Returns the event distributor.
 EventDispatcher getEventDispatcher()
          Returns the attribute eventDispatcher.
 java.lang.String getGameName()
          Returns the name of the game.
 ObjectManager getObjectManager()
          Returns the instance of the ObjectManager.
 PeerManager getPeerManager()
          Returns the peerManager on the current peer.
 java.lang.String getPlayerName()
          Returns the name of the player.
 GameSetup getSetup()
          Returns the setup of the game
 TimerRegistry getTimerRegistry()
          Gets the associated timer registry object.
 void initGame()
          Is a foward call of initGame() on a GameSetup object.
 void joinGame(java.net.InetAddress[] inetad, int[] port, java.lang.String password)
          This method is used, to join a game using inetadresses and ports.
 void joinGame(java.lang.String[] names, java.net.Socket[] connections)
          Adds the given peers to the PeerManager and creates a WorldStateRequestEvent.
 void loadCharacter(java.lang.String playerName, java.io.File file)
          Loads a saved character to continue with it in a new mission.
 void loadGame(java.io.File file)
          Loads a saved game to resume a mission.
 void newPeer(java.net.InetAddress inetad, int port, java.lang.String password)
          Adds a new peer with name, ip-address and portnumber to the PeerManager.
 void newPeer(java.lang.String name, java.net.Socket connection)
          Adds a new peer to the PeerManager with name and the socket
 void newPeerConnectionServer(int portNumber, java.lang.String password)
          Creates a new instance of a peer server list to given port.
 void processEvent(Event event)
          The parameter event is the Event which is processed.
 void saveCharacter(java.lang.String playerName, java.io.File file)
          Saves the Character specified in playerName to the file.
 void saveGame(java.io.File file)
          Saves the current game to the file.
 void setPlayerName(java.lang.String name)
          Set the playerName of the current game.
 void setSetup(GameSetup setup)
          Set's the Setup class of the Game (GameSetup) to the attribute "setup" which is used by many of the other methods in this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameManager

public GameManager(java.lang.String gameName,
                   java.lang.String playerName)
The constructor to create a instance of the GameManager.
Parameters:
gameName - The name of the game
playerName - The name of the player which starts the game
Preconditions:
gameName != "" and playerName != ""
Method Detail

initGame

public void initGame()
Is a foward call of initGame() on a GameSetup object.
Preconditions:
setup != null

processEvent

public void processEvent(Event event)
The parameter event is the Event which is processed. Possible events are:WorldStateRequestEvent, WorldStateEvent,PeerDeadEvent
Specified by:
processEvent in interface EventSink
Parameters:
event - The event which is processed
Preconditions:
setup != null
Event != null
See Also:
<{WorldStateRequestEvent}>, <{WorldStateEvent}>, <{PeerDeadEvent}>

newPeerConnectionServer

public void newPeerConnectionServer(int portNumber,
                                    java.lang.String password)
Creates a new instance of a peer server list to given port.
Parameters:
password - String the password for joining the game. "" means no password
portNumber - the port number where the server should listen for connections
Preconditions:
portNumber != 0

newPeer

public void newPeer(java.lang.String name,
                    java.net.Socket connection)
Adds a new peer to the PeerManager with name and the socket
Parameters:
name - The name of the new peer
connection - is the socket for the connection
Preconditions:
name != ""
connection != null
See Also:
<{Socket}>, <{PeerManager}>

newPeer

public void newPeer(java.net.InetAddress inetad,
                    int port,
                    java.lang.String password)
             throws WrongPasswordException
Adds a new peer with name, ip-address and portnumber to the PeerManager.
Parameters:
password - String password for the joining game. "" means no password.
inetad - InetAddress, to connect with
port - Portnumber of remote peer
Throws:
WrongPasswordException - If the password was wrong this exception is thrown.
Preconditions:
name != ""
inetd != null
port != 0
See Also:
<{PeerManager}>

joinGame

public void joinGame(java.lang.String[] names,
                     java.net.Socket[] connections)
Adds the given peers to the PeerManager and creates a WorldStateRequestEvent. It also calls the processEvent method on the remoteDispatcher.
Parameters:
names - Array of new peers
connections - Array of Sockets
Preconditions:
names != null
connections != null
See Also:
<{Socket}>, <{PeerManager}>

joinGame

public void joinGame(java.net.InetAddress[] inetad,
                     int[] port,
                     java.lang.String password)
              throws WrongPasswordException
This method is used, to join a game using inetadresses and ports.
Parameters:
password - String the password for joining a game. "" means no password.
inetad - Array of corresponding inetaddresses
port - Array of corresponding port-numbers
Throws:
WrongPasswordException - If the password was wrong this exception is thrown.
Preconditions:
names.getLength()==inetad.getLength()==port.getLength()
names != null
inetad != null
port != null

getGameName

public java.lang.String getGameName()
Returns the name of the game.
Returns:
name of the running game

getPlayerName

public java.lang.String getPlayerName()
Returns the name of the player.
Returns:
the name of player running this instance

getObjectManager

public ObjectManager getObjectManager()
Returns the instance of the ObjectManager.
Returns:
a ObjectManager instance
See Also:
<{ObjectManager}>

setSetup

public void setSetup(GameSetup setup)
Set's the Setup class of the Game (GameSetup) to the attribute "setup" which is used by many of the other methods in this class.
Parameters:
setup - A GameSetup object
Preconditions:
setup != null
Postconditions:
self.setup != null

getEventDispatcher

public EventDispatcher getEventDispatcher()
Returns the attribute eventDispatcher.
Returns:
A EventDispatcher object.
See Also:
<{EventDispatcher}>

getTimerRegistry

public TimerRegistry getTimerRegistry()
Gets the associated timer registry object.
Returns:
The timer registry.

loadGame

public void loadGame(java.io.File file)
Loads a saved game to resume a mission.
Parameters:
file - The file, with absolut path, from which the game should be loaded
Preconditions:
setup != null

saveGame

public void saveGame(java.io.File file)
Saves the current game to the file.
Parameters:
file - the file with absolute path to which the ddata is stored

loadCharacter

public void loadCharacter(java.lang.String playerName,
                          java.io.File file)
Loads a saved character to continue with it in a new mission.
Parameters:
playerName - The name of the character to be loaded
file - The file from which the character will be loaded
Preconditions:
setup != null
gameName != ""

saveCharacter

public void saveCharacter(java.lang.String playerName,
                          java.io.File file)
Saves the Character specified in playerName to the file.
Parameters:
playerName - the name of the character
file - data is saved to this file

eventDistributor

public EventDistributor eventDistributor()
Returns the event distributor.
Specified by:
eventDistributor in interface EventSource
Returns:
the event distributor

setPlayerName

public void setPlayerName(java.lang.String name)
Set the playerName of the current game.
Parameters:
name - String specifies the player name.

getSetup

public GameSetup getSetup()
Returns the setup of the game
Returns:
the game setup
See Also:
<{GameSetup}>

getPeerManager

public PeerManager getPeerManager()
Returns the peerManager on the current peer.
Returns:
the peer manager
See Also:
<{PeerManager}>



This page is hosted by the Chair for Applied Software Engineering of the Technische Universität München.
Imprint (Impressum)