Class games.Battle.shared.comm.GameInfo
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class games.Battle.shared.comm.GameInfo

java.lang.Object
   |
   +----games.Battle.shared.comm.BattlePacket
           |
           +----games.Battle.shared.comm.GameInfo

public class GameInfo
extends BattlePacket
GameInfo encapsulates all the knowledge about a particular game on the server. The GameInfo packet knows which players have joined the game, how many are still needed to start the game, and what the gameId of the game is.

The server transmits a series of GameInfo packets to the client so that the user can choose which game they would like to join. Once a game is full of players, the game is automatically started by the server, and the players can only quit by forfeiting the game.


Variable Index

 o players
The game keeps an array of players that have joined so far.

Constructor Index

 o GameInfo()
Construct an empty GameInfo packet so that it can be read from an input stream.
 o GameInfo(int)
Construct a new GameInfo packet, including making a new ID.

Method Index

 o equals(Object)
 o fromBytes(byte[])
Produce a GameInfo from an array of bytes.
 o getId()
Returns this game's unique identifier
 o hashCode()
 o isRunning()
Returns true if the game is full of all the players it needs.
 o join(PlayerInfo)
Allows a new player to join this game.
 o numberJoined()
Returns how many players have joined this game.
 o numberNeeded()
Returns how many players are needed to fill this game.
 o quit(PlayerInfo)
Allows a player to get out of this game.
 o readFrom(InputStream)
Read this GameInfo from the InputStream given.
 o reset()
Empties all the players out of this game.
 o toBytes()
Produce an array of bytes representing a GameInfo
 o toString()
Returns a string representation of this game.
 o writeTo(OutputStream)
Write this GameInfo to the OutputStream given.

Variables

 o players
  public PlayerInfo players[]
The game keeps an array of players that have joined so far.

Constructors

 o GameInfo
  public GameInfo()
Construct an empty GameInfo packet so that it can be read from an input stream.
 o GameInfo
  public GameInfo(int numPlayers)
Construct a new GameInfo packet, including making a new ID.
Parameters:
numPlayers - the number of players needed to start this game

Methods

 o isRunning
  public boolean isRunning()
Returns true if the game is full of all the players it needs.
 o reset
  public synchronized void reset()
Empties all the players out of this game.
 o join
  public synchronized void join(PlayerInfo p)
Allows a new player to join this game.
 o quit
  public synchronized void quit(PlayerInfo p)
Allows a player to get out of this game.
 o numberNeeded
  public int numberNeeded()
Returns how many players are needed to fill this game.
 o numberJoined
  public int numberJoined()
Returns how many players have joined this game.
 o getId
  public int getId()
Returns this game's unique identifier
 o toBytes
  public byte[] toBytes()
Produce an array of bytes representing a GameInfo
Overrides:
toBytes in class BattlePacket
 o fromBytes
  public void fromBytes(byte buffer[])
Produce a GameInfo from an array of bytes.
Overrides:
fromBytes in class BattlePacket
 o writeTo
  public void writeTo(OutputStream os) throws IOException
Write this GameInfo to the OutputStream given. Overrides the base class so that we can easily write out the embedded PlayerInfo objects.
Parameters:
os - the output stream that the info packet is written to
Overrides:
writeTo in class BattlePacket
 o readFrom
  public int readFrom(InputStream is) throws IOException
Read this GameInfo from the InputStream given. Overrides the base class so that we can easily read in the embedded PlayerInfo objects.
Parameters:
is - the input stream that the info packet is read from
Overrides:
readFrom in class BattlePacket
 o toString
  public String toString()
Returns a string representation of this game.
Overrides:
toString in class Object
 o hashCode
  public int hashCode()
Overrides:
hashCode in class Object
 o equals
  public boolean equals(Object other)
Overrides:
equals in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index