8 /* Open the highscore file: */
14 #include "high_scores.h"
19 FILE * opendata(char * mode)
25 filename = (char *) malloc(sizeof(char) * (strlen(st_dir) +
26 strlen("/st_highscore.dat") + 1));
28 strcpy(filename, st_dir);
29 /* Open the high score file: */
33 strcat(filename, "/highscore");
37 strcat(filename, "/st_highscore.dat");
42 /* Try opening the file: */
44 fi = fopen(filename, mode);
49 fprintf(stderr, "Warning: I could not open the high score file ");
51 if (strcmp(mode, "r") == 0)
52 fprintf(stderr, "for read!!!\n");
53 else if (strcmp(mode, "w") == 0)
54 fprintf(stderr, "for write!!!\n");
61 /* Load data from high score file: */
69 strcpy(hs_name, "Grandma\0");
72 /* Try to open file: */
79 fgets(temp, sizeof(temp), fi);
83 temp[strlen(temp) - 1] = '\0';
86 /* Parse each line: */
88 if (strstr(temp, "highscore=") == temp)
90 hs_score = atoi(temp + 10);
95 if (strstr(temp, "name=") == temp)
97 fprintf(stderr, "name found\n");
98 strl = strlen("name=");
100 for(c = strl; c < strlen(temp); c++)
101 hs_name[c-strl] = temp[c];
111 void save_hs(int score)
114 texture_load(&bkgd, DATA_PREFIX "/images/highscore/highscore.png", IGNORE_ALPHA);
118 /* ask for player's name */
119 menumenu = MENU_HIGHSCORE;
124 texture_draw_bg(&bkgd, NO_UPDATE);
128 while(SDL_PollEvent(&event))
129 if(event.type == SDL_KEYDOWN)
130 menu_event(&event.key.keysym);
136 /* Try to open file: */
141 fprintf(fi, "# Supertux highscore file\n\n");
143 fprintf(fi, "name=%s\n", hs_name);
144 fprintf(fi, "highscore=%d\n", hs_score);
146 fprintf(fi, "# (File automatically created.)\n");