8 /* Open the highscore file: */
14 #include "high_scores.h"
21 const char * highscore_filename = "/st_highscore.dat";
23 const char * highscore_filename = "/highscore";
27 char hs_name[62]; /* highscores global variables*/
29 /* Load data from high score file: */
39 strcpy(hs_name, "Grandma\0");
42 /* Try to open file: */
44 fi = opendata(highscore_filename, "r");
49 fgets(temp, sizeof(temp), fi);
53 temp[strlen(temp) - 1] = '\0';
56 /* Parse each line: */
58 if (strstr(temp, "highscore=") == temp)
60 hs_score = atoi(temp + 10);
65 if (strstr(temp, "name=") == temp)
67 fprintf(stderr, "name found\n");
68 strl = strlen("name=");
69 for(c = strl, i = 0; c < strlen(temp); ++c, ++i)
81 void save_hs(int score)
90 texture_load(&bkgd, datadir + "/images/highscore/highscore.png", IGNORE_ALPHA);
95 Menu::set_current(highscore_menu);
97 if(!highscore_menu->item[0].input)
98 highscore_menu->item[0].input = (char*) malloc(strlen(hs_name) + 1);
100 strcpy(highscore_menu->item[0].input,hs_name);
102 /* ask for player's name */
106 texture_draw_bg(&bkgd);
108 text_drawf(&blue_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
109 text_draw(&blue_text, "Your score:", 150, 180, 1, NO_UPDATE);
110 sprintf(str, "%d", hs_score);
111 text_draw(&yellow_nums, str, 350, 170, 1, NO_UPDATE);
113 menu_process_current();
116 while(SDL_PollEvent(&event))
117 if(event.type == SDL_KEYDOWN)
120 switch (highscore_menu->check())
123 if(highscore_menu->item[0].input != NULL)
124 strcpy(hs_name, highscore_menu->item[0].input);
132 /* Try to open file: */
134 fi = opendata(highscore_filename, "w");
137 fprintf(fi, "# Supertux highscore file\n\n");
139 fprintf(fi, "name=%s\n", hs_name);
140 fprintf(fi, "highscore=%d\n", hs_score);
142 fprintf(fi, "# (File automatically created.)\n");