3
FILE *Scorelist::open_file(char *mode) {
4
return fopen (XBILL_SCORE, mode);
7
void Scorelist::read() {
8
FILE *scorefile = open_file("r");
11
for (i=0; i<10; i++) {
12
fgets (name[i], 21, scorefile);
13
fscanf (scorefile, "%d%d\n", &(level[i]), &(score[i]));
18
for (i=0; i<10; i++) {
19
strcpy(name[i], "me");
20
level[i] = score[i] = 0;
24
void Scorelist::write() {
26
FILE *scorefile = open_file("w");
27
if (!scorefile) return;
28
for (i=0; i<10; i++) {
29
fputs(name[i], scorefile);
30
for (j=strlen(name[i]); j<25; j++)
31
fputc(' ', scorefile);
32
fprintf (scorefile, " %d %d\n", level[i], score[i]);
37
/* Add new high score to list */
38
void Scorelist::recalc (char *str) {
40
if (score[9] >= game.score) return;
42
if (score[i-1] < game.score) {
43
strcpy (name[i], name[i-1]);
44
level[i] = level[i-1];
45
score[i] = score[i-1];
49
strcpy (name[i], str);
50
level[i] = game.level;
51
score[i] = game.score;
54
void Scorelist::update() {
55
char str[500], temp[40];
57
strcpy (str,"High Scores:\n\n");
58
strcat (str, "Name Level Score\n");
59
for (i=0; i<10; i++) {
60
strcat (str, name[i]);
61
for (j=strlen(name[i]); j<21; j++) strcat (str, " ");
64
if (score[i] > 9999999)
66
sprintf (temp, "%5d %7d\n", level[i], score[i]);