Richard Ellingworth / Mbed 2 deprecated RobotRic

Dependencies:   25LCxxx_SPI CommonTypes Gameduino mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HighScoreTable.h Source File

HighScoreTable.h

00001 /*
00002  * SOURCE FILE : HighScoreTable.h
00003  *
00004  * Definition of class HighScoreTable.
00005  * Maintains a table of high scores with a name and a score for each entry in the table.
00006  *
00007  */
00008 
00009 #ifndef HighScoreTableDefined
00010 
00011   #define HighScoreTableDefined
00012 
00013   #include "Types.h"
00014   #include "PlayerName.h"
00015   #include "Ser25lcxxx.h"       // serial EEPROM routines. Also work for 25AAxxx EEPROMs.
00016   
00017   class HighScoreTable {
00018 
00019   public :
00020 
00021     /***************/
00022     /* CONSTRUCTOR */
00023     /***************/
00024     // Pass pointer to an SPI EEPROM which contains the high scores.
00025     HighScoreTable( Ser25LCxxx *e );
00026 
00027     /**************/
00028     /* DESTRUCTOR */
00029     /**************/
00030     virtual ~HighScoreTable();
00031 
00032     /***************************************/
00033     /* GET EEPROM USED BY HIGH SCORE TABLE */
00034     /***************************************/
00035     Ser25LCxxx *GetEEPROM( void ) const {
00036         return eeprom;
00037     }
00038         
00039     /****************************************/
00040     /* VALIDATE EEPROM USED FOR HIGH SCORES */
00041     /****************************************/
00042     // Checks EEPROM used for high scores and
00043     // if any of it looks like nonsense it
00044     // rewrites the whole table with defaults.
00045     void ValidateEEPROM( void );
00046 
00047     /********************************/
00048     /* DETERMINE IF EEPROM IS VALID */
00049     /********************************/
00050     // Returns true if EEPROM is valid.
00051     bool EEPROMValid( void );
00052     
00053     /****************************/
00054     /* WRITE DEFAULTS TO EEPROM */
00055     /****************************/
00056     void WriteEEPROMDefaults( void );
00057     
00058     /*************************/
00059     /* GET CAPACITY OF TABLE */
00060     /*************************/
00061     // Returns capacity of table.
00062     UInt8 GetCapacity( void ) const {
00063       return capacity;
00064     }
00065     
00066     /**********************************************/
00067     /* DETERMINE POSITION OF A SCORE IN THE TABLE */
00068     /**********************************************/
00069     // Pass score in score.
00070     // Returns position in table (0 is top score).
00071     // If position returned is >= capacity of table then score is not high
00072     // enough to place in table.
00073     UInt8 GetPositionInTable( UInt32 score ) const;
00074     
00075     /*********************************/
00076     /* ADD ENTRY TO HIGH SCORE TABLE */
00077     /*********************************/
00078     // Pass position in table to put entry in pos.
00079     // Pass name of player in name.
00080     // Pass score in score.
00081     void Add( UInt8 pos, const PlayerName *name, UInt32 score );
00082 
00083     /****************************/
00084     /* GET ENTRY FROM THE TABLE */
00085     /****************************/
00086     // Pass position to fetch from in pos.
00087     // Player name is returned in object pointed to by name.
00088     // Player score is returned in integer pointed to by score.
00089     void Get( UInt8 pos, PlayerName *name, UInt32 *score ) const;
00090     
00091   private :
00092 
00093     // Change the following to suit.
00094     enum {
00095         eepromAddress = 0,    // address in EEPROM where high score table starts
00096         capacity = 10,        // number of entries in table
00097         // Amount of memory used in EEPROM.
00098         // You need capacity bytes for the index and then
00099         // eight bytes for each high score and name.
00100         memoryUsed = capacity + ( capacity << 3 ),
00101     };
00102 
00103     // Pointer to EEPROM that holds high scores.
00104     Ser25LCxxx *eeprom;
00105         
00106   };
00107 
00108 #endif
00109 
00110 /* END of HighScoreTable.h */