Score Struct Reference


Public Methods

struct Score* Score_ctor (struct Score *ptr_score, struct Module *ptr_module)
void Score_dtor (struct Score *ptr_score, int memory_flag)
bool Score_is_valid (struct Score *ptr_score)
int Score_get_record_count (struct Score *ptr_score)
bool Score_read (struct Score *ptr_score, int index, struct score_t *ptr_result)
bool Score_write (struct Score *ptr_score, int index, struct score_t *ptr_result)
bool Score_write_Ex (struct Score *ptr_score, int index, long score, char *sz_nickname, cyid_t cyid, time_t time)


Detailed Description

The game's high score archive.

See also:
score_t, Miscellaneous


Member Function Documentation

struct Score * Score_ctor ( struct Score * ptr_score,
struct Module * ptr_module )
 

High score archive constructor.
Before using this object, you must add an uncompressed "score.inf" file to the application archive. Specify its size as (number of records)*20 bytes. To disable file compression, use "-" before "score.inf" in the filer's file list.

Parameters:
ptr_score   A pointer to the high score archive structure
ptr_module   A pointer to the application's thread module
Returns:
A pointer to the initialized high score archive object
       #include <cybiko.h>
       ...
       int index;
       int record_number;
       struct module_t main_module;
       struct Score score_archive;
       struct score_t* high_scores;
       ...
       init_module( &main_module );
       ...
       Score_ctor( &score_archive, main_module.m_process->module );
       if( Score_is_valid ( &score_archive ) )
       {
         record_number = Score_get_record_count( &score_archive );
         high_scores = (struct score_t*)malloc( sizeof(struct score_t)*record_number );
         for( index = 0; index < record_number; index ++ )
         {
           Score_read( &score_archive, index, high_scores + index );
         }
         //  Changes high_scores.
         ...
         for( index = 0; index < record_number; index ++ )
         {
           Score_write( &score_archive, index, high_scores + index );
         }
         ...
         free(high_scores);
       }
       ...
       Score_dtor( &score_archive, LEAVE_MEMORY );
       ...

void Score_dtor ( struct Score * ptr_score,
int memory_flag )
 

High score archive destructor.

Parameters:
ptr_score   A pointer to the initialized high score archive object.
memory_flag   Can be FREE_MEMORY or LEAVE_MEMORY. If the memory was allocated for the object by malloc(), use FREE_MEMORY to free it. Use LEAVE_MEMORY If the object was static or allocated in a stack
Returns:
None
       #include <cybiko.h>
       ...
       int index;
       int record_number;
       struct module_t main_module;
       struct Score score_archive;
       struct score_t* high_scores;
       ...
       init_module( &main_module );
       ...
       Score_ctor( &score_archive, main_module.m_process->module );
       if( Score_is_valid ( &score_archive ) )
       {
         record_number = Score_get_record_count( &score_archive );
         high_scores = (struct score_t*)malloc( sizeof(struct score_t)*record_number );
         for( index = 0; index < record_number; index ++ )
         {
           Score_read( &score_archive, index, high_scores + index );
         }
         //  Changes high_scores.
         ...
         for( index = 0; index < record_number; index ++ )
         {
           Score_write( &score_archive, index, high_scores + index );
         }
         ...
         free(high_scores);
       }
       ...
       Score_dtor( &score_archive, LEAVE_MEMORY );
       ...
See also:
FREE_MEMORY, LEAVE_MEMORY.

int Score_get_record_count ( struct Score * ptr_score )
 

Returns the number of records in the high score archive.

Parameters:
ptr_score   A pointer to the initialized high score archive object
Returns:
Number of records in the high score archive
       #include <cybiko.h>
       ...
       int index;
       int record_number;
       struct module_t main_module;
       struct Score score_archive;
       struct score_t* high_scores;
       ...
       init_module( &main_module );
       ...
       Score_ctor( &score_archive, main_module.m_process->module );
       if( Score_is_valid ( &score_archive ) )
       {
         record_number = Score_get_record_count( &score_archive );
         high_scores = (struct score_t*)malloc( sizeof(struct score_t)*record_number );
         for( index = 0; index < record_number; index ++ )
         {
           Score_read( &score_archive, index, high_scores + index );
         }
         //  Changes high_scores.
         ...
         for( index = 0; index < record_number; index ++ )
         {
           Score_write( &score_archive, index, high_scores + index );
         }
         ...
         free(high_scores);
       }
       ...
       Score_dtor( &score_archive, LEAVE_MEMORY );
       ...

bool Score_is_valid ( struct Score * ptr_score )
 

Checks the validity of the high score archive.

Parameters:
ptr_score   A pointer to the initialized high score archive object
Returns:
TRUE if the high score archive is valid, otherwise FALSE
       #include <cybiko.h>
       ...
       int index;
       int record_number;
       struct module_t main_module;
       struct Score score_archive;
       struct score_t* high_scores;
       ...
       init_module( &main_module );
       ...
       Score_ctor( &score_archive, main_module.m_process->module );
       if( Score_is_valid ( &score_archive ) )
       {
         record_number = Score_get_record_count( &score_archive );
         high_scores = (struct score_t*)malloc( sizeof(struct score_t)*record_number );
         for( index = 0; index < record_number; index ++ )
         {
           Score_read( &score_archive, index, high_scores + index );
         }
         //  Changes high_scores.
         ...
         for( index = 0; index < record_number; index ++ )
         {
           Score_write( &score_archive, index, high_scores + index );
         }
         ...
         free(high_scores);
       }
       ...
       Score_dtor( &score_archive, LEAVE_MEMORY );
       ...

bool Score_read ( struct Score * ptr_score,
int index,
struct score_t * ptr_result )
 

Reads the record from the high score archive.

Parameters:
ptr_score   A pointer to the initialized high score archive object
index   The index of the record in the high score archive
ptr_result   A pointer to the buffer that receives the score
Returns:
TRUE if the record was read successfully
       #include <cybiko.h>
       ...
       int index;
       int record_number;
       struct module_t main_module;
       struct Score score_archive; 
       struct score_t* high_scores; 
       ...
       init_module( &main_module );
       ...
       Score_ctor( &score_archive, main_module.m_process->module );
       if( Score_is_valid ( &score_archive ) )
       {
         record_number = Score_get_record_count( &score_archive );
         high_scores = (struct score_t*)malloc( sizeof(struct score_t)*record_number );
         for( index = 0; index < record_number; index ++ )
         {
           Score_read( &score_archive, index, high_scores + index );
         }
         //  Changes high_scores. 
         ...
         for( index = 0; index < record_number; index ++ )
         {
           Score_write( &score_archive, index, high_scores + index );
         }
         ...
         free(high_scores);
       }
       ...
       Score_dtor( &score_archive, LEAVE_MEMORY );
       ...
See also:
score_t.

bool Score_write ( struct Score * ptr_score,
int index,
struct score_t * ptr_result )
 

Writes the record to the high score archive.

Parameters:
ptr_score   Pointer to the initialized high score archive object
index   Index of the record in the high score archive
ptr_result   A pointer to the game's high score structure
Returns:
TRUE if the record was stored successfully
       #include <cybiko.h>
       ...
       int index;
       int record_number;
       struct module_t main_module;
       struct Score score_archive;
       struct score_t* high_scores;
       ...
       init_module( &main_module );
       ...
       Score_ctor( &score_archive, main_module.m_process->module );
       if( Score_is_valid ( &score_archive ) )
       {
         record_number = Score_get_record_count( &score_archive );
         high_scores = (struct score_t*)malloc( sizeof(struct score_t)*record_number );
         for( index = 0; index < record_number; index ++ )
         {
           Score_read( &score_archive, index, high_scores + index );
         }
         //  Changes high_scores.
         ...
         for( index = 0; index < record_number; index ++ )
         {
           Score_write( &score_archive, index, high_scores + index );
         }
         ...
         free(high_scores);
       }
       ...
       Score_dtor( &score_archive, LEAVE_MEMORY );
       ...
See also:
Score_write_Ex, score_t.

bool Score_write_Ex ( struct Score * ptr_score,
int index,
long score,
char * sz_nickname,
cyid_t cyid,
time_t time )
 

Writes the record to the high score archive.

Parameters:
ptr_score   A pointer to the initialized high score archive object
index   The index of the record in the high score archive
score   The high score value
sz_nickname   The Cy name of the player, who has reached the high score
cyid   The Cy ID of the device on which the score was reached
time   Time the high score was reached
Returns:
TRUE if the record was stored successfully.
       #include <cybiko.h>
       ...
       int index;
       int record_number;
       struct module_t main_module;
       struct Score score_archive;
       struct score_t* high_scores;
       ...
       init_module( &main_module );
       ...
       Score_ctor( &score_archive, main_module.m_process->module );
       if( Score_is_valid ( &score_archive ) )
       {
         record_number = Score_get_record_count( &score_archive );
         high_scores = (struct score_t*)malloc( sizeof(struct score_t)*record_number );
         for( index = 0; index < record_number; index ++ )
         {
           Score_read( &score_archive, index, high_scores + index );
         }
         //  Changes high_scores.
         ...
         for( index = 0; index < record_number; index ++ )
         {
           Score_write_Ex( &score_archive,
                           index,
                           high_scores[index].score,
                           high_scores[index].nickname,
                           high_scores[index].cyid,
                           high_scores[index].time );
         }
         ...
         free(high_scores);
       }
       ...
       Score_dtor( &score_archive, LEAVE_MEMORY );
       ...
See also:
Score_write, score_t.