diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-03 21:26:17 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-03 21:26:17 +0000 |
| commit | 2fd0c9d50f1eb83d46080fb114cba5465e8c4506 (patch) | |
| tree | 69d3aef56532f0a96c5d1b9b2800167152f239ca /src/heightScore.c | |
| parent | f18096a5c43d5cc52670c24d73d3efeebb120307 (diff) | |
- zaciatok podpory FR jazyka
- server podporuje socre ( treb este zdokumentovat protokol )
- prelozene dve chybove hlasky pre siete
- odosielam to na rychlo
git-svn-id: http://opensvn.csie.org/tuxanci_ng@59 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/heightScore.c')
| -rw-r--r-- | src/heightScore.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/heightScore.c b/src/heightScore.c new file mode 100644 index 0000000..fa7402e --- /dev/null +++ b/src/heightScore.c @@ -0,0 +1,98 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include "main.h" +#include "list.h" +#include "textFile.h" +#include "heightScore.h" + +static textFile_t *textFile; + +void initHeightScore(char *file) +{ + int i; + + textFile = loadTextFile(file); + + if( textFile == NULL ) + { + fprintf(stderr, "I can't load %s !\n", file); + fprintf(stderr, "I create %s\n", file); + textFile = newTextFile(file); + } + else + { + return; + } + + if( textFile == NULL ) + { + fprintf(stderr, "I can't create %s!\n", file); + return; + } + + for( i = 0 ; i < HEIGHTSCORE_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 < HEIGHTSCORE_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, HEIGHTSCORE_MAX_PLAYERS, free); + 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 quitHeightScore() +{ + if( textFile != NULL ) + { + saveTextFile(textFile); + destroyTextFile(textFile); + } +} |