Package net.sf.freecol.common.model
Class HighScore
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.HighScore
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public class HighScore extends FreeColObject
A FreeCol high score record.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HighScore.ScoreLevel
On retirement, an object will be named in honour of the player.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
COLONIES_TAG
private java.util.Date
date
The date for this score.private static java.lang.String
DATE_TAG
private java.text.SimpleDateFormat
dateFormat
The format to use for dates.static java.util.Comparator<? super HighScore>
descendingScoreComparator
A comparator by ascending AI object value.private java.lang.String
difficulty
The difficulty level of this game.private static java.lang.String
DIFFICULTY_TAG
private java.util.UUID
gameUUID
The game UUID.private static java.lang.String
GAMEUUID_TAG
private static java.lang.String
HIGH_SCORES_TAG
private static java.lang.String
INDEPENDENCE_TURN_TAG
private int
independenceTurn
The turn in which independence was granted.private HighScore.ScoreLevel
level
The ScoreLevel/title for this score.private static java.lang.String
LEVEL_TAG
private static java.util.logging.Logger
logger
private static java.lang.String
NATION_ID_TAG
private static java.lang.String
NATION_NAME_TAG
private static java.lang.String
NATION_TYPE_ID_TAG
private java.lang.String
nationId
The nation that retired.private java.lang.String
nationName
The name given to the new independent nation.private java.lang.String
nationTypeId
The nation type that retired.private int
nColonies
The final number of colonies.private static java.lang.String
NEW_LAND_NAME_TAG
private java.lang.String
newLandName
The name for the New World.private static java.util.UUID
nullUUID
Trivial UUID to used when it is not present in the high score file.static int
NUMBER_OF_HIGH_SCORES
The number of high scores to allow in the high scores list.private int
nUnits
The final number of units.private static java.lang.String
PLAYER_NAME_TAG
private java.lang.String
playerName
The name of the human player.private static java.lang.String
RETIREMENT_TURN_TAG
private int
retirementTurn
The turn when the player retired.private int
score
The high score.private static java.lang.String
SCORE_TAG
static java.lang.String
TAG
private static java.lang.String
UNITS_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description HighScore()
Trivial constructor, for Game.newInstance.HighScore(FreeColXMLReader xr)
Create a newHighScore
by reading a stream.HighScore(Player player)
Create a new high score record.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int
checkHighScore(HighScore highScore, java.util.List<HighScore> scores)
Can a given score be added to a high score list.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.int
getColonyCount()
Get the number of colonies.java.util.Date
getDate()
Get the date.java.lang.String
getDateString()
Get theDate
the score was achieved as a formatted string.java.lang.String
getDifficulty()
Get the game difficulty key.java.util.UUID
getGameUUID()
Get the game UUID.int
getIndependenceTurn()
Get the turn independence occurs.HighScore.ScoreLevel
getLevel()
Get theScoreLevel
corresponding to the score.java.lang.String
getNationId()
Get the nation identifier.java.lang.String
getNationName()
Get the independent nation name.java.lang.String
getNationTypeId()
Get the nation type identifier.java.lang.String
getNewLandName()
Get the name given to the New World.java.lang.String
getOldNationNameKey()
Get the original nation localized name key.java.lang.String
getPlayerName()
Get the player name.int
getRetirementTurn()
Get the turn the player retired.int
getScore()
Get the final score.int
getUnitCount()
Get number of units.java.lang.String
getXMLTagName()
Get the serialization tag for this object.static java.util.List<HighScore>
loadHighScores()
Load the high scores.static boolean
newHighScore(Player player)
Tries to adds a new high score for player.void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.static boolean
saveHighScores(java.util.List<HighScore> scores)
Saves high scores.private static void
tidyScores(java.util.List<HighScore> scores)
Tidy a list of scores into canonical form.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSpecification, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readChild, readChildren, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, setSpecification, toString, toXML, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
nullUUID
private static final java.util.UUID nullUUID
Trivial UUID to used when it is not present in the high score file.
-
descendingScoreComparator
public static final java.util.Comparator<? super HighScore> descendingScoreComparator
A comparator by ascending AI object value.
-
NUMBER_OF_HIGH_SCORES
public static final int NUMBER_OF_HIGH_SCORES
The number of high scores to allow in the high scores list.- See Also:
- Constant Field Values
-
dateFormat
private final java.text.SimpleDateFormat dateFormat
The format to use for dates. Almost ISO8601.
-
independenceTurn
private int independenceTurn
The turn in which independence was granted.
-
playerName
private java.lang.String playerName
The name of the human player.
-
nationId
private java.lang.String nationId
The nation that retired.
-
nationTypeId
private java.lang.String nationTypeId
The nation type that retired.
-
gameUUID
private java.util.UUID gameUUID
The game UUID.
-
score
private int score
The high score.
-
level
private HighScore.ScoreLevel level
The ScoreLevel/title for this score.
-
nationName
private java.lang.String nationName
The name given to the new independent nation.
-
difficulty
private java.lang.String difficulty
The difficulty level of this game.
-
nUnits
private int nUnits
The final number of units.
-
nColonies
private int nColonies
The final number of colonies.
-
newLandName
private java.lang.String newLandName
The name for the New World.
-
date
private java.util.Date date
The date for this score.
-
retirementTurn
private int retirementTurn
The turn when the player retired.
-
HIGH_SCORES_TAG
private static final java.lang.String HIGH_SCORES_TAG
- See Also:
- Constant Field Values
-
COLONIES_TAG
private static final java.lang.String COLONIES_TAG
- See Also:
- Constant Field Values
-
DATE_TAG
private static final java.lang.String DATE_TAG
- See Also:
- Constant Field Values
-
DIFFICULTY_TAG
private static final java.lang.String DIFFICULTY_TAG
- See Also:
- Constant Field Values
-
GAMEUUID_TAG
private static final java.lang.String GAMEUUID_TAG
- See Also:
- Constant Field Values
-
INDEPENDENCE_TURN_TAG
private static final java.lang.String INDEPENDENCE_TURN_TAG
- See Also:
- Constant Field Values
-
LEVEL_TAG
private static final java.lang.String LEVEL_TAG
- See Also:
- Constant Field Values
-
NATION_ID_TAG
private static final java.lang.String NATION_ID_TAG
- See Also:
- Constant Field Values
-
NATION_NAME_TAG
private static final java.lang.String NATION_NAME_TAG
- See Also:
- Constant Field Values
-
NATION_TYPE_ID_TAG
private static final java.lang.String NATION_TYPE_ID_TAG
- See Also:
- Constant Field Values
-
NEW_LAND_NAME_TAG
private static final java.lang.String NEW_LAND_NAME_TAG
- See Also:
- Constant Field Values
-
PLAYER_NAME_TAG
private static final java.lang.String PLAYER_NAME_TAG
- See Also:
- Constant Field Values
-
RETIREMENT_TURN_TAG
private static final java.lang.String RETIREMENT_TURN_TAG
- See Also:
- Constant Field Values
-
SCORE_TAG
private static final java.lang.String SCORE_TAG
- See Also:
- Constant Field Values
-
UNITS_TAG
private static final java.lang.String UNITS_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HighScore
public HighScore()
Trivial constructor, for Game.newInstance.
-
HighScore
public HighScore(Player player)
Create a new high score record. Public for the test suite.- Parameters:
player
- ThePlayer
the score is for.
-
HighScore
public HighScore(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Create a newHighScore
by reading a stream.- Parameters:
xr
- TheFreeColXMLReader
to read.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
-
Method Detail
-
getIndependenceTurn
public final int getIndependenceTurn()
Get the turn independence occurs.- Returns:
- The independence turn.
-
getRetirementTurn
public final int getRetirementTurn()
Get the turn the player retired.- Returns:
- The retirement turn.
-
getPlayerName
public final java.lang.String getPlayerName()
Get the player name.- Returns:
- The player name.
-
getNationId
public final java.lang.String getNationId()
Get the nation identifier.- Returns:
- The nation identifier.
-
getNationTypeId
public final java.lang.String getNationTypeId()
Get the nation type identifier.- Returns:
- The nation type identifier.
-
getGameUUID
public final java.util.UUID getGameUUID()
Get the game UUID.- Returns:
- The UUID for the game with this score.
-
getScore
public final int getScore()
Get the final score.- Returns:
- The score.
-
getLevel
public final HighScore.ScoreLevel getLevel()
Get theScoreLevel
corresponding to the score.- Returns:
- The score level.
-
getOldNationNameKey
public final java.lang.String getOldNationNameKey()
Get the original nation localized name key.- Returns:
- The old name key.
-
getNationName
public final java.lang.String getNationName()
Get the independent nation name.- Returns:
- The independent nation name.
-
getNewLandName
public final java.lang.String getNewLandName()
Get the name given to the New World.- Returns:
- The new land name.
-
getDifficulty
public final java.lang.String getDifficulty()
Get the game difficulty key.- Returns:
- The game difficulty key.
-
getUnitCount
public final int getUnitCount()
Get number of units.- Returns:
- The number of units.
-
getColonyCount
public final int getColonyCount()
Get the number of colonies.- Returns:
- The number of colonies.
-
getDate
public final java.util.Date getDate()
Get the date.- Returns:
- The date.
-
getDateString
public final java.lang.String getDateString()
Get theDate
the score was achieved as a formatted string.- Returns:
- The date string.
-
tidyScores
private static void tidyScores(java.util.List<HighScore> scores)
Tidy a list of scores into canonical form. That is, sorted and with no more that NUMBER_OF_HIGH_SCORES members.- Parameters:
scores
- The list ofHighScore
s to operate on.
-
checkHighScore
public static int checkHighScore(HighScore highScore, java.util.List<HighScore> scores)
Can a given score be added to a high score list.- Parameters:
highScore
- TheHighScore
to check.scores
- A list ofHighScore
to check against.- Returns:
- The index of a score to replace, or negative if no replacement.
-
newHighScore
public static boolean newHighScore(Player player)
Tries to adds a new high score for player.- Parameters:
player
- ThePlayer
to add a high score for.- Returns:
- True if the score was high enough to be added to the high score list.
-
loadHighScores
public static java.util.List<HighScore> loadHighScores()
Load the high scores.- Returns:
- A list of
HighScore
s from the high score file.
-
saveHighScores
public static boolean saveHighScores(java.util.List<HighScore> scores)
Saves high scores.- Parameters:
scores
- The list ofHighScore
s to save.- Returns:
- True if the high scores were saved to the high score file.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColObject
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributes
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
public void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
-