bluegammon.logic
Class GameRecord

java.lang.Object
  extended bybluegammon.logic.GameRecord

public class GameRecord
extends java.lang.Object

A game record represents one or multiple games between an opponent, keeping track of scores and such. GameRecords are stored in the RMS.

The static interface of this class provides a hash table like functionality and also contains logic for keeping the limit of maximum allowed game records.

Author:
Peter Andersson

Method Summary
static int countRecords()
          Returns number of records saved in the rms.
static java.util.Vector getAllRecords()
          Returns a vector of GameRecords, containing all stored game records.
 int getGameCount()
          Returns number of games played agains opponent represented in this record.
 int getIndex()
          Returns the index in rms that this record occupies.
 int getOpponentId()
          Returns the id of the opponent represented in this record.
 char[] getOpponentName()
          Returns the name of the opponent represented in this record.
 int getOpponentScore()
          Returns the score of the opponent represented in this record.
 int getPlayerScore()
          Returns the score of the player represented in this record.
static GameRecord getRecord(Player opponent)
          Returns record for a specific opponent.
static byte[] getSavedGame(int id)
          Returns the data of a saved game.
 long getTimestamp()
          Returns the time of the latest change to this record.
static void saveGame(Player opponent, byte[] savedGame)
          Saves the state of an ongoing game against specified opponents.
static void updateGameResult(Player opponent, boolean localWinner, int score)
          Updates the game results with a new game.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTimestamp

public long getTimestamp()
Returns the time of the latest change to this record.

Returns:
The timestamp.

getOpponentId

public int getOpponentId()
Returns the id of the opponent represented in this record.

Returns:
The opponent id.

getOpponentName

public char[] getOpponentName()
Returns the name of the opponent represented in this record.

Returns:
The opponent name.

getOpponentScore

public int getOpponentScore()
Returns the score of the opponent represented in this record.

Returns:
The opponent score.

getPlayerScore

public int getPlayerScore()
Returns the score of the player represented in this record.

Returns:
The player score.

getGameCount

public int getGameCount()
Returns number of games played agains opponent represented in this record.

Returns:
Number of games against opponent.

getIndex

public int getIndex()
Returns the index in rms that this record occupies.

Returns:
The rms index.

getSavedGame

public static byte[] getSavedGame(int id)
Returns the data of a saved game.

Parameters:
id - The opponent id.
Returns:
The saved game data or null if there is no saved game data for an opponent with specified id.

saveGame

public static void saveGame(Player opponent,
                            byte[] savedGame)
Saves the state of an ongoing game against specified opponents.

Parameters:
opponent - The opponent player.
savedGame - The saved game data.

countRecords

public static int countRecords()
Returns number of records saved in the rms.

Returns:
Number of stored game records.

getAllRecords

public static java.util.Vector getAllRecords()
Returns a vector of GameRecords, containing all stored game records.

Returns:
All stored game records.

getRecord

public static GameRecord getRecord(Player opponent)
Returns record for a specific opponent. If the player has not played against this opponent before, null is returned.

Parameters:
opponent - The opponent.
Returns:
The GameRecord for this opponent, or null if it does not exist.

updateGameResult

public static void updateGameResult(Player opponent,
                                    boolean localWinner,
                                    int score)
Updates the game results with a new game.

Parameters:
opponent - The opponent player.
localWinner - If this game was won by local player.
score - The score.