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)
89 bkgd = new Surface(datadir + "/images/highscore/highscore.png", IGNORE_ALPHA);
94 Menu::set_current(highscore_menu);
96 if(!highscore_menu->item[0].input)
97 highscore_menu->item[0].input = (char*) malloc(strlen(hs_name) + 1);
99 strcpy(highscore_menu->item[0].input,hs_name);
101 /* ask for player's name */
107 text_drawf(&blue_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
108 text_draw(&blue_text, "Your score:", 150, 180, 1, NO_UPDATE);
109 sprintf(str, "%d", hs_score);
110 text_draw(&yellow_nums, str, 350, 170, 1, NO_UPDATE);
112 menu_process_current();
115 while(SDL_PollEvent(&event))
116 if(event.type == SDL_KEYDOWN)
117 current_menu->event(event);
119 switch (highscore_menu->check())
122 if(highscore_menu->item[0].input != NULL)
123 strcpy(hs_name, highscore_menu->item[0].input);
131 /* Try to open file: */
133 fi = opendata(highscore_filename, "w");
136 fprintf(fi, "# Supertux highscore file\n\n");
138 fprintf(fi, "name=%s\n", hs_name);
139 fprintf(fi, "highscore=%d\n", hs_score);
141 fprintf(fi, "# (File automatically created.)\n");