diff options
Diffstat (limited to 'src/server/highScore.c')
| -rw-r--r-- | src/server/highScore.c | 107 |
1 files changed, 51 insertions, 56 deletions
diff --git a/src/server/highScore.c b/src/server/highScore.c index 1ae7001..37c87b4 100644 --- a/src/server/highScore.c +++ b/src/server/highScore.c @@ -11,85 +11,80 @@ static textFile_t *textFile; -void -initHighScore(char *file) +void initHighScore(char *file) { - int i; + int i; - textFile = loadTextFile(file); + textFile = loadTextFile(file); - if (textFile == NULL) { - fprintf(stderr, _("I am unable to load: \"%s\"!\n"), file); - fprintf(stderr, _("Creating: \"%s\"\n"), file); - textFile = newTextFile(file); - } - else { + if (textFile == NULL) { + fprintf(stderr, _("I am unable to load: \"%s\"!\n"), file); + fprintf(stderr, _("Creating: \"%s\"\n"), file); + textFile = newTextFile(file); + } else { #ifdef DEBUG - printf(_("Scorefile: \"%s\"\n"), file); + printf(_("Scorefile: \"%s\"\n"), file); #endif - return; - } + return; + } - if (textFile == NULL) { - fprintf(stderr, _("I was unable to create: \"%s\"!\n"), file); - return; - } + if (textFile == NULL) { + fprintf(stderr, _("I was unable to create: \"%s\"!\n"), file); + return; + } - for (i = 0; i < HIGHSCORE_MAX_PLAYERS; i++) { - addList(textFile->text, strdup("no_name 0")); - } + for (i = 0; i < HIGHSCORE_MAX_PLAYERS; i++) { + addList(textFile->text, strdup("no_name 0")); + } - saveTextFile(textFile); + saveTextFile(textFile); } -int -addPlayerInHighScore(char *name, int score) +int addPlayerInHighScore(char *name, int score) { - int i; + int i; - if (score <= 0) { - return -1; // Ha ha ha - } + if (score <= 0) { + return -1; // Ha ha ha + } - for (i = 0; i < HIGHSCORE_MAX_PLAYERS; i++) { - char *line; - char thisName[STR_NAME_SIZE]; - int thisCore; + for (i = 0; i < HIGHSCORE_MAX_PLAYERS; i++) { + char *line; + char thisName[STR_NAME_SIZE]; + int thisCore; - line = (char *) textFile->text->list[i]; - sscanf(line, "%s %d", thisName, &thisCore); + line = (char *) textFile->text->list[i]; + sscanf(line, "%s %d", thisName, &thisCore); - if (score >= thisCore) { - char new[STR_SIZE]; + if (score >= thisCore) { + char new[STR_SIZE]; - sprintf(new, "%s %d", name, score); - insList(textFile->text, i, strdup(new)); - delListItem(textFile->text, HIGHSCORE_MAX_PLAYERS, free); - //printTextFile(textFile); - saveTextFile(textFile); + sprintf(new, "%s %d", name, score); + insList(textFile->text, i, strdup(new)); + delListItem(textFile->text, HIGHSCORE_MAX_PLAYERS, free); + //printTextFile(textFile); + saveTextFile(textFile); - return 0; - } - } + return 0; + } + } - return -1; + return -1; } -char * -getTableItem(int index) +char *getTableItem(int index) { - if (textFile != NULL && index >= 0 && index < textFile->text->count) { - return (char *) textFile->text->list[index]; - } + if (textFile != NULL && index >= 0 && index < textFile->text->count) { + return (char *) textFile->text->list[index]; + } - return NULL; + return NULL; } -void -quitHighScore() +void quitHighScore() { - if (textFile != NULL) { - saveTextFile(textFile); - destroyTextFile(textFile); - } + if (textFile != NULL) { + saveTextFile(textFile); + destroyTextFile(textFile); + } } |