Version of Robotron arcade game using LPC1768, a Gameduino shield, a serial EEPROM (for high scores), two microswitch joysticks and two buttons plus a box to put it in. 20 levels of mayhem.
Dependencies: 25LCxxx_SPI CommonTypes Gameduino mbed
Diff: HighScoreTable.h
- Revision:
- 0:5fa232ee5fdf
- Child:
- 2:bb0f631a6068
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HighScoreTable.h Tue Jun 04 20:16:33 2013 +0000 @@ -0,0 +1,111 @@ +/* + * SOURCE FILE : HighScoreTable.h + * + * Definition of class HighScoreTable. + * Maintains a table of high scores with a name and a score for each entry in the table. + * + */ + +#ifndef HighScoreTableDefined + + #define HighScoreTableDefined + + #include "Types.h" + #include "PlayerName.h" + #include "I2CEEPROM.h" + + class HighScoreTable { + + public : + + /***************/ + /* CONSTRUCTOR */ + /***************/ + // Pass pointer to an I2C EEPROM which contains the high scores. + HighScoreTable( I2CEEPROM *e ); + + /**************/ + /* DESTRUCTOR */ + /**************/ + virtual ~HighScoreTable(); + + /***************************************/ + /* GET EEPROM USED BY HIGH SCORE TABLE */ + /***************************************/ + I2CEEPROM *GetEEPROM( void ) const { + return eeprom; + } + + /****************************************/ + /* VALIDATE EEPROM USED FOR HIGH SCORES */ + /****************************************/ + // Checks EEPROM used for high scores and + // if any of it looks like nonsense it + // rewrites the whole table with defaults. + void ValidateEEPROM( void ); + + /********************************/ + /* DETERMINE IF EEPROM IS VALID */ + /********************************/ + // Returns true if EEPROM is valid. + bool EEPROMValid( void ); + + /*************************/ + /* GET CAPACITY OF TABLE */ + /*************************/ + // Returns capacity of table. + UInt8 GetCapacity( void ) const { + return capacity; + } + + /**********************************************/ + /* DETERMINE POSITION OF A SCORE IN THE TABLE */ + /**********************************************/ + // Pass score in score. + // Returns position in table (0 is top score). + // If position returned is >= capacity of table then score is not high + // enough to place in table. + UInt8 GetPositionInTable( UInt32 score ) const; + + /*********************************/ + /* ADD ENTRY TO HIGH SCORE TABLE */ + /*********************************/ + // Pass position in table to put entry in pos. + // Pass name of player in name. + // Pass score in score. + void Add( UInt8 pos, const PlayerName *name, UInt32 score ); + + /****************************/ + /* GET ENTRY FROM THE TABLE */ + /****************************/ + // Pass position to fetch from in pos. + // Player name is returned in object pointed to by name. + // Player score is returned in integer pointed to by score. + void Get( UInt8 pos, PlayerName *name, UInt32 *score ) const; + + private : + + // Change the following to suit. + enum { + eepromAddress = 0, // address in EEPROM where high score table starts + capacity = 10, // number of entries in table + // Amount of memory used in EEPROM. + // You need capacity bytes for the index and then + // eight bytes for each high score and name. + memoryUsed = capacity + ( capacity << 3 ), + }; + + // Pointer to EEPROM that holds high scores. + I2CEEPROM *eeprom; + + /****************************/ + /* WRITE DEFAULTS TO EEPROM */ + /****************************/ + void WriteEEPROMDefaults( void ); + + }; + +#endif + +/* END of HighScoreTable.h */ +