~ubuntu-branches/ubuntu/hardy/xbill/hardy

« back to all changes in this revision

Viewing changes to Scorelist.cc

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Bridgett
  • Date: 2004-09-07 09:52:14 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040907095214-d0m46ojc8f7upuqm
Tags: 2.1-4
maintainer upload of NMU - many thanks Tollef (closes: #268885) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "objects.h"
2
 
 
3
 
FILE *Scorelist::open_file(char *mode) {
4
 
        return fopen (XBILL_SCORE, mode);
5
 
}
6
 
 
7
 
void Scorelist::read() {
8
 
        FILE *scorefile = open_file("r");
9
 
        int i;
10
 
        if (scorefile) {
11
 
                for (i=0; i<10; i++) {
12
 
                        fgets (name[i], 21, scorefile);
13
 
                        fscanf (scorefile, "%d%d\n", &(level[i]), &(score[i]));
14
 
                }
15
 
                fclose(scorefile);
16
 
        }
17
 
        else
18
 
                for (i=0; i<10; i++) {
19
 
                        strcpy(name[i], "me");
20
 
                        level[i] = score[i] = 0;
21
 
                }
22
 
}
23
 
 
24
 
void Scorelist::write() {
25
 
        int i, j;
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]);
33
 
        }
34
 
        fclose(scorefile);
35
 
}
36
 
 
37
 
/*  Add new high score to list   */
38
 
void Scorelist::recalc (char *str) {
39
 
        int i;
40
 
        if (score[9] >= game.score) return;
41
 
        for (i=9; i>0; i--) {
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];
46
 
                }
47
 
                else break;
48
 
        }
49
 
        strcpy (name[i], str);
50
 
        level[i] = game.level;
51
 
        score[i] = game.score;
52
 
}
53
 
 
54
 
void Scorelist::update() {
55
 
        char str[500], temp[40];
56
 
        int i, j;
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, " ");
62
 
                if (level[i] > 99999)
63
 
                        level[i]=99999;
64
 
                if (score[i] > 9999999)
65
 
                        score[i]=9999999;
66
 
                sprintf (temp, "%5d  %7d\n", level[i], score[i]);
67
 
                strcat (str, temp);
68
 
        }
69
 
        ui.update_hsbox(str);
70
 
}
71