Features: Add and view records, auto-sort, find average score, autosaves data to file, simple to use, *new* Allegro frontend.
Requirements: A C++ compiler
AllegroHighScore is a class which provides you with an easy way of implementing a highscore system, with a graphical interface, into your Allegro game. AllegroHighScore saves your highscore table to a file when you close your game, and opens it back up when you start your game again.
MAX_RECORDS Maximum amount of high scores. WARNING!!!! Delete the current scores data file before changing this value. NAME_LENGTH Maxium amount of characters for name. WARNING!!!! Delete the current scores data file before changing this value. EMPTY_RECORD_NAME This is the string that is used for the name of an emtpy record FILE_NAME String containing the name of the binary file to save highscores TEXT_COLOR The text color.
int allegroEnterRecord(int score); Prompts user to enter their name (if their score is high enough) graphicly, then adds their record in the appropriate position. It returns 0 if users score doesn't qualify for highscores or it returns 1 if users score is successfully entered into the highscore table. void allegroDisplayAllRecords(); Graphicly displays the highscores table to the screen. int addRecord(char name[NAME_LENGTH], int score); Adds a record in the apropriate position based on the size of its score. It returns 0 if users score doesn't qualify for highscores or it returns 1 if users score is successfully entered into the highscore table. int viewRecordScore(int position); Returns the score at the requested position. char * viewRecordName(int position); Returns the name for the requested position. int findAverageScore(); Finds the average score of all of the records in the highscore table and returns the average. void clearAllRecords(); Clears the entire highscores table. int testRecord(int score); With the given score, this function: a) Returns 1 if the score qualifies for the highscores. b) Returns 0 if the score does not qualify for the highscores.
#include#include #include"alleghs.h" //The highscore headerfile. int main(){ //Our score variable int score=9000; //creates an object allegroHighScore highscore; //Intialize Allegro allegro_init(); install_keyboard(); set_gfx_mode(GFX_AUTODETECT,640,480,0,0); //when this function is called, a screen will come up, asking the user... //...to enter his/her name (if the score is high enough). highscore.allegroEnterRecord(score); //displays entire highscore table until escape is hit highscore.allegroDisplayAllRecords(); while(key[KEY_ESC]==0){} //Deinitialize Allegro remove_keyboard(); allegro_exit(); return 0; }
#include#include"hiscore.h" //The HighScore header file, dont forget this void main() { //Create our HighScore table HighScore myHighScore; //This function resets the highscore table myHighScore.clearAllRecords(); //This function adds a record. It does all the sorting //for you. It returns 1 on a successful addition, or 0 if the //record doesn't qualify for the highscores (the score isn't high enough) myHighScore.addRecord("jack",5000); //This function returns the name at the given position cout<<myHighScore.viewRecordName(2)<<endl; //This function returns the score at the given position cout<<myHighScore.viewRecordScore(2)<<endl; //This fuction returns the average score of all the records cout<<myHighScore.findAverageScore()<<endl; //Returns 0 if the given score isn't good enough for the highscores //or one if it is. cout<<myHighScore.testRecord(5000)<<;endl; }
If you have any comments, suggestions, or requests dealing with my class, please email me at:
gameprogrammer@excite.com
Drop by my website:
http://justin-todd.tripod.com/
Shawn Hargreaves for the excellent graphics library, Allegro.
DJ Delorie for the excellent C++ compiler.