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.
-
players
- The game keeps an array of players that have joined so far.
-
GameInfo()
- Construct an empty GameInfo packet so that it can be read from an
input stream.
-
GameInfo(int)
- Construct a new GameInfo packet, including making a new ID.
-
equals(Object)
-
-
fromBytes(byte[])
- Produce a GameInfo from an array of bytes.
-
getId()
- Returns this game's unique identifier
-
hashCode()
-
-
isRunning()
- Returns true if the game is full of all the players it needs.
-
join(PlayerInfo)
- Allows a new player to join this game.
-
numberJoined()
- Returns how many players have joined this game.
-
numberNeeded()
- Returns how many players are needed to fill this game.
-
quit(PlayerInfo)
- Allows a player to get out of this game.
-
readFrom(InputStream)
- Read this GameInfo from the InputStream given.
-
reset()
- Empties all the players out of this game.
-
toBytes()
- Produce an array of bytes representing a GameInfo
-
toString()
- Returns a string representation of this game.
-
writeTo(OutputStream)
- Write this GameInfo to the OutputStream given.
players
public PlayerInfo players[]
- The game keeps an array of players that have joined so far.
GameInfo
public GameInfo()
- Construct an empty GameInfo packet so that it can be read from an
input stream.
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
isRunning
public boolean isRunning()
- Returns true if the game is full of all the players it needs.
reset
public synchronized void reset()
- Empties all the players out of this game.
join
public synchronized void join(PlayerInfo p)
- Allows a new player to join this game.
quit
public synchronized void quit(PlayerInfo p)
- Allows a player to get out of this game.
numberNeeded
public int numberNeeded()
- Returns how many players are needed to fill this game.
numberJoined
public int numberJoined()
- Returns how many players have joined this game.
getId
public int getId()
- Returns this game's unique identifier
toBytes
public byte[] toBytes()
- Produce an array of bytes representing a GameInfo
- Overrides:
- toBytes in class BattlePacket
fromBytes
public void fromBytes(byte buffer[])
- Produce a GameInfo from an array of bytes.
- Overrides:
- fromBytes in class BattlePacket
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
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
toString
public String toString()
- Returns a string representation of this game.
- Overrides:
- toString in class Object
hashCode
public int hashCode()
- Overrides:
- hashCode in class Object
equals
public boolean equals(Object other)
- Overrides:
- equals in class Object
All Packages Class Hierarchy This Package Previous Next Index