diff options
| author | xHire <xhire@tuxportal.cz> | 2008-10-25 11:58:43 +0200 |
|---|---|---|
| committer | xHire <xhire@tuxportal.cz> | 2008-10-25 11:58:43 +0200 |
| commit | 03daa19ec574dcab59e89566a8062b60b16a8325 (patch) | |
| tree | 702273f2e42d4e483a5262f66660d8b3329e558e /src/server/highScore.c | |
| parent | 4b4a75f6ced29923777d0dd7e27fdd4bbfed800a (diff) | |
Translated all game into Czech + some small fixes
Updated scripts
Correction: "Height Score" -> "High Score"
Set right file permissions
Diffstat (limited to 'src/server/highScore.c')
| -rw-r--r-- | src/server/highScore.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/server/highScore.c b/src/server/highScore.c new file mode 100644 index 0000000..1ae7001 --- /dev/null +++ b/src/server/highScore.c @@ -0,0 +1,95 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include "main.h" +#include "list.h" +#include "textFile.h" +#include "highScore.h" + +static textFile_t *textFile; + +void +initHighScore(char *file) +{ + int i; + + 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 { +#ifdef DEBUG + printf(_("Scorefile: \"%s\"\n"), file); +#endif + 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")); + } + + saveTextFile(textFile); +} + +int +addPlayerInHighScore(char *name, int score) +{ + int i; + + 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; + + line = (char *) textFile->text->list[i]; + sscanf(line, "%s %d", thisName, &thisCore); + + 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); + + return 0; + } + } + + return -1; +} + +char * +getTableItem(int index) +{ + if (textFile != NULL && index >= 0 && index < textFile->text->count) { + return (char *) textFile->text->list[index]; + } + + return NULL; +} + +void +quitHighScore() +{ + if (textFile != NULL) { + saveTextFile(textFile); + destroyTextFile(textFile); + } +} |