Class HighScore

    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • 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.
      • 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.
      • INDEPENDENCE_TURN_TAG

        private static final java.lang.String INDEPENDENCE_TURN_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
      • RETIREMENT_TURN_TAG

        private static final java.lang.String RETIREMENT_TURN_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 - The Player the score is for.
      • HighScore

        public HighScore​(FreeColXMLReader xr)
                  throws javax.xml.stream.XMLStreamException
        Create a new HighScore by reading a stream.
        Parameters:
        xr - The FreeColXMLReader 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 the ScoreLevel 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 the Date 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 of HighScores 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 - The HighScore to check.
        scores - A list of HighScore 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 - The Player 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 HighScores from the high score file.
      • saveHighScores

        public static boolean saveHighScores​(java.util.List<HighScore> scores)
        Saves high scores.
        Parameters:
        scores - The list of HighScores 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 class FreeColObject
        Type Parameters:
        T - The FreeColObject 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 class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Returns:
        The tag.