Primarily keeps track of read-only game data loaded from XML files and readable/writable data stored in databases. Secondarily provides functionality for more repeatable random number generation and access to the current real world time.
Authors: David Herzka, John Kline, Daniel Koverman
The Resources class parses XML documents to retrieve Images, Animations, Sounds, Integers, Doubles, and Strings. These are stored in maps and retrievable using a string key. An example XML document can be found in the src.examples.resource.resourcesxmlexample package for formatting concerns. The Resources class also allows for adding Resources on an individual basis. Data required to launch the game window (width, height, and full screen true/false) can also be loaded separately from the other resources using loadPreLaunchData(). All data that can be handled using Resources should be handled using Resources.
The use of ResourceModules is in development. ResoureModules should allow for the addition of new types of resources without modification to the Resources class.
The DBHandler class allows for basic interactions with an SQLite database. Currently, its functionality includes creating tables, fetching columns, and adding and deleting table rows. Different types of data can be stored in the database columns as dictated by the built-in data type constants in the Column class. As SQLite is loosely typed, it is usually fine to use the "NONE" data type for all columns.
Real world time is kept using the static WorldClock class which
allows for setting a local time zone and determining the time at that
time zone as well as individual components of time ranging from the
current millisecond to the current year. These times are also available
in UTC/system time. This allows for the game to change based on real
world variables such as time of day or time of year.
@see WorldClock
If repeatability is a concern when generating random numbers, the Randomizer class should be used. Randomizer allows static access to a random number generator which means that all random number generation in the game can be tied to the same generator. This allows the value of one seed to govern the behavior of the entire game. There is functionality for reverting back to previous seeds and starting secondary random number generators for when repeatability is not an issue.
Importation of data is performed using the DataHandler class. The
DataHandler class is abstract and acts as a template for a data loading
subclass. It contains a Data HashMap
@see DataHandler
HighScoreHandler is a class that deals with data that must be
both accessed and written. The API includes a systematic way to
interface with a database, but the high score list feature is a common
enough one to warrant its own class. This class, which initialized,
creates a highscores table in the desired database file if one does not
already exist and populates it with zeros. The list can be maintained at
any length desired. The updateScores(...) method checks whether an input
score belongs on the list and adds it if it does (while removing the
previous lowest entry). The list of scores, their corresponding player
names, and the time at which the score was set can be retrieved from the
class with the getScores(), getNames(), and getTimes() accessor methods.
@HighScoreHandler
All random number handling for the game should be handled using
the static Randomizer class. Randomizer is based on the java.util.Random
class and has all of the same functionality plus the ability to store
and reset seeds in order to facilitate replays. All random numbers in a
game that might require exact replication in order to replay should be
generated using this class. Random numbers which do not require exact
replication, such as aesthetic or particle effects, can also be
generated with this class using secondary random paths.
@Randomizer
@since 1.6