#include <string.h>
#include <stdio.h>
#include "hiscore.h"

#define SIZE 10

hse hiscore[SIZE];

void ini_hiscore()
{
    size_t i;

    for(i = 0; i < SIZE; i++) {  
        strcpy(hiscore[i].initials, "...");
        hiscore[i].score = 0;
    }
}

void add_score(int p_score, char p_initials[4])
{
    hse new_entry;
    
    new_entry.score = p_score;
    strcpy(new_entry.initials, p_initials);
    
    hiscore[SIZE - 1].score = new_entry.score;
    strcpy(hiscore[SIZE - 1].initials, new_entry.initials);
}

void sort_hiscore()
{
    size_t j;
    int pass;
    hse hold;

    for(pass = 1; pass < SIZE; pass++) {
        for(j = SIZE - 1; j > 0; j--) {
            if(hiscore[j].score > hiscore[j - 1].score) {
                hold = hiscore[j];
                hiscore[j] = hiscore[j - 1];
                hiscore[j - 1] = hold;
            }
        }
    }
}

int qualify(int p_score)
{        
    return p_score > hiscore[SIZE - 1].score;
}

hse get_entry(int i)
{
    return hiscore[i];
}

