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

Committer:
RichardE
Date:
Mon Jun 17 15:10:43 2013 +0000
Revision:
18:70190f956a24
Parent:
17:194789db2215
Improved response to button 1 when entering high scores (HighScoreEntry.cpp).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RichardE 0:5fa232ee5fdf 1 /*
RichardE 0:5fa232ee5fdf 2 * SOURCE FILE : HighScoreTable.h
RichardE 0:5fa232ee5fdf 3 *
RichardE 0:5fa232ee5fdf 4 * Definition of class HighScoreTable.
RichardE 0:5fa232ee5fdf 5 * Maintains a table of high scores with a name and a score for each entry in the table.
RichardE 0:5fa232ee5fdf 6 *
RichardE 0:5fa232ee5fdf 7 */
RichardE 0:5fa232ee5fdf 8
RichardE 0:5fa232ee5fdf 9 #ifndef HighScoreTableDefined
RichardE 0:5fa232ee5fdf 10
RichardE 0:5fa232ee5fdf 11 #define HighScoreTableDefined
RichardE 0:5fa232ee5fdf 12
RichardE 0:5fa232ee5fdf 13 #include "Types.h"
RichardE 0:5fa232ee5fdf 14 #include "PlayerName.h"
RichardE 3:a6a0cd726ca0 15 #include "Ser25lcxxx.h" // serial EEPROM routines. Also work for 25AAxxx EEPROMs.
RichardE 0:5fa232ee5fdf 16
RichardE 0:5fa232ee5fdf 17 class HighScoreTable {
RichardE 0:5fa232ee5fdf 18
RichardE 0:5fa232ee5fdf 19 public :
RichardE 0:5fa232ee5fdf 20
RichardE 0:5fa232ee5fdf 21 /***************/
RichardE 0:5fa232ee5fdf 22 /* CONSTRUCTOR */
RichardE 0:5fa232ee5fdf 23 /***************/
RichardE 3:a6a0cd726ca0 24 // Pass pointer to an SPI EEPROM which contains the high scores.
RichardE 3:a6a0cd726ca0 25 HighScoreTable( Ser25LCxxx *e );
RichardE 0:5fa232ee5fdf 26
RichardE 0:5fa232ee5fdf 27 /**************/
RichardE 0:5fa232ee5fdf 28 /* DESTRUCTOR */
RichardE 0:5fa232ee5fdf 29 /**************/
RichardE 0:5fa232ee5fdf 30 virtual ~HighScoreTable();
RichardE 0:5fa232ee5fdf 31
RichardE 2:bb0f631a6068 32 /***************************************/
RichardE 2:bb0f631a6068 33 /* GET EEPROM USED BY HIGH SCORE TABLE */
RichardE 2:bb0f631a6068 34 /***************************************/
RichardE 3:a6a0cd726ca0 35 Ser25LCxxx *GetEEPROM( void ) const {
RichardE 2:bb0f631a6068 36 return eeprom;
RichardE 2:bb0f631a6068 37 }
RichardE 0:5fa232ee5fdf 38
RichardE 0:5fa232ee5fdf 39 /****************************************/
RichardE 0:5fa232ee5fdf 40 /* VALIDATE EEPROM USED FOR HIGH SCORES */
RichardE 0:5fa232ee5fdf 41 /****************************************/
RichardE 0:5fa232ee5fdf 42 // Checks EEPROM used for high scores and
RichardE 0:5fa232ee5fdf 43 // if any of it looks like nonsense it
RichardE 0:5fa232ee5fdf 44 // rewrites the whole table with defaults.
RichardE 0:5fa232ee5fdf 45 void ValidateEEPROM( void );
RichardE 0:5fa232ee5fdf 46
RichardE 0:5fa232ee5fdf 47 /********************************/
RichardE 0:5fa232ee5fdf 48 /* DETERMINE IF EEPROM IS VALID */
RichardE 0:5fa232ee5fdf 49 /********************************/
RichardE 0:5fa232ee5fdf 50 // Returns true if EEPROM is valid.
RichardE 0:5fa232ee5fdf 51 bool EEPROMValid( void );
RichardE 0:5fa232ee5fdf 52
RichardE 17:194789db2215 53 /****************************/
RichardE 17:194789db2215 54 /* WRITE DEFAULTS TO EEPROM */
RichardE 17:194789db2215 55 /****************************/
RichardE 17:194789db2215 56 void WriteEEPROMDefaults( void );
RichardE 17:194789db2215 57
RichardE 3:a6a0cd726ca0 58 /*************************/
RichardE 0:5fa232ee5fdf 59 /* GET CAPACITY OF TABLE */
RichardE 0:5fa232ee5fdf 60 /*************************/
RichardE 0:5fa232ee5fdf 61 // Returns capacity of table.
RichardE 0:5fa232ee5fdf 62 UInt8 GetCapacity( void ) const {
RichardE 0:5fa232ee5fdf 63 return capacity;
RichardE 0:5fa232ee5fdf 64 }
RichardE 0:5fa232ee5fdf 65
RichardE 0:5fa232ee5fdf 66 /**********************************************/
RichardE 0:5fa232ee5fdf 67 /* DETERMINE POSITION OF A SCORE IN THE TABLE */
RichardE 0:5fa232ee5fdf 68 /**********************************************/
RichardE 0:5fa232ee5fdf 69 // Pass score in score.
RichardE 0:5fa232ee5fdf 70 // Returns position in table (0 is top score).
RichardE 0:5fa232ee5fdf 71 // If position returned is >= capacity of table then score is not high
RichardE 0:5fa232ee5fdf 72 // enough to place in table.
RichardE 0:5fa232ee5fdf 73 UInt8 GetPositionInTable( UInt32 score ) const;
RichardE 0:5fa232ee5fdf 74
RichardE 0:5fa232ee5fdf 75 /*********************************/
RichardE 0:5fa232ee5fdf 76 /* ADD ENTRY TO HIGH SCORE TABLE */
RichardE 0:5fa232ee5fdf 77 /*********************************/
RichardE 0:5fa232ee5fdf 78 // Pass position in table to put entry in pos.
RichardE 0:5fa232ee5fdf 79 // Pass name of player in name.
RichardE 0:5fa232ee5fdf 80 // Pass score in score.
RichardE 0:5fa232ee5fdf 81 void Add( UInt8 pos, const PlayerName *name, UInt32 score );
RichardE 0:5fa232ee5fdf 82
RichardE 0:5fa232ee5fdf 83 /****************************/
RichardE 0:5fa232ee5fdf 84 /* GET ENTRY FROM THE TABLE */
RichardE 0:5fa232ee5fdf 85 /****************************/
RichardE 0:5fa232ee5fdf 86 // Pass position to fetch from in pos.
RichardE 0:5fa232ee5fdf 87 // Player name is returned in object pointed to by name.
RichardE 0:5fa232ee5fdf 88 // Player score is returned in integer pointed to by score.
RichardE 0:5fa232ee5fdf 89 void Get( UInt8 pos, PlayerName *name, UInt32 *score ) const;
RichardE 0:5fa232ee5fdf 90
RichardE 0:5fa232ee5fdf 91 private :
RichardE 0:5fa232ee5fdf 92
RichardE 0:5fa232ee5fdf 93 // Change the following to suit.
RichardE 0:5fa232ee5fdf 94 enum {
RichardE 2:bb0f631a6068 95 eepromAddress = 0, // address in EEPROM where high score table starts
RichardE 2:bb0f631a6068 96 capacity = 10, // number of entries in table
RichardE 2:bb0f631a6068 97 // Amount of memory used in EEPROM.
RichardE 2:bb0f631a6068 98 // You need capacity bytes for the index and then
RichardE 2:bb0f631a6068 99 // eight bytes for each high score and name.
RichardE 2:bb0f631a6068 100 memoryUsed = capacity + ( capacity << 3 ),
RichardE 0:5fa232ee5fdf 101 };
RichardE 0:5fa232ee5fdf 102
RichardE 2:bb0f631a6068 103 // Pointer to EEPROM that holds high scores.
RichardE 3:a6a0cd726ca0 104 Ser25LCxxx *eeprom;
RichardE 0:5fa232ee5fdf 105
RichardE 0:5fa232ee5fdf 106 };
RichardE 0:5fa232ee5fdf 107
RichardE 0:5fa232ee5fdf 108 #endif
RichardE 0:5fa232ee5fdf 109
RichardE 0:5fa232ee5fdf 110 /* END of HighScoreTable.h */