3
FILE *Scorelist::open_file(char *mode) {
5
sprintf (file, "%sscores", XBILL_HOME);
6
return fopen (file, mode);
9
void Scorelist::read() {
10
FILE *scorefile = open_file("r");
13
for (i=0; i<10; i++) {
14
fgets (name[i], 21, scorefile);
15
fscanf (scorefile, "%d%d\n", &(level[i]), &(score[i]));
20
for (i=0; i<10; i++) {
21
strcpy(name[i], "me");
22
level[i] = score[i] = 0;
26
void Scorelist::write() {
28
FILE *scorefile = open_file("w");
29
if (!scorefile) return;
30
for (i=0; i<10; i++) {
31
fputs(name[i], scorefile);
32
for (j=strlen(name[i]); j<25; j++)
33
fputc(' ', scorefile);
34
fprintf (scorefile, " %d %d\n", level[i], score[i]);
39
/* Add new high score to list */
40
void Scorelist::recalc (char *str) {
42
if (score[9] >= game.score) return;
44
if (score[i-1] < game.score) {
45
strcpy (name[i], name[i-1]);
46
level[i] = level[i-1];
47
score[i] = score[i-1];
51
strcpy (name[i], str);
52
level[i] = game.level;
53
score[i] = game.score;
56
void Scorelist::update() {
57
char str[500], temp[40];
59
strcpy (str,"High Scores:\n\n");
60
strcat (str, "Name Level Score\n");
61
for (i=0; i<10; i++) {
62
strcat (str, name[i]);
63
for (j=strlen(name[i]); j<21; j++) strcat (str, " ");
64
sprintf (temp, "%5d %7d\n", level[i], score[i]);