#include "menu.h"
#include "screen.h"
#include "texture.h"
+#include "setup.h"
-int hs_score;
-char hs_name[62]; /* highscores global variables*/
-
-FILE * opendata(char * mode)
-{
- char * filename = NULL;
- FILE * fi;
-
-
- filename = (char *) malloc(sizeof(char) * (strlen(st_dir) +
- strlen("/st_highscore.dat") + 1));
-
- strcpy(filename, st_dir);
- /* Open the high score file: */
-
-#ifndef WIN32
- strcat(filename, "/highscore");
+#ifdef WIN32
+const char * highscore_filename = "/st_highscore.dat";
#else
- strcat(filename, "/st_highscore.dat");
+const char * highscore_filename = "/highscore";
#endif
-
- /* Try opening the file: */
-
- fi = fopen(filename, mode);
- free( filename );
-
- if (fi == NULL)
- {
- fprintf(stderr, "Warning: Unable to open the high score file ");
-
- if (strcmp(mode, "r") == 0)
- fprintf(stderr, "for read!!!\n");
- else if (strcmp(mode, "w") == 0)
- fprintf(stderr, "for write!!!\n");
-
- }
-
- return(fi);
-}
+int hs_score;
+char hs_name[62]; /* highscores global variables*/
/* Load data from high score file: */
/* Try to open file: */
- fi = opendata("r");
+ fi = opendata(highscore_filename, "r");
if (fi != NULL)
{
do
hs_score = score;
menu_reset();
- menu_set_current(&highscore_menu);
+ Menu::set_current(highscore_menu);
- if(!highscore_menu.item[0].input)
- highscore_menu.item[0].input = (char*) malloc(strlen(hs_name) + 1);
+ if(!highscore_menu->item[0].input)
+ highscore_menu->item[0].input = (char*) malloc(strlen(hs_name) + 1);
- strcpy(highscore_menu.item[0].input,hs_name);
+ strcpy(highscore_menu->item[0].input,hs_name);
/* ask for player's name */
show_menu = 1;
while(show_menu)
{
- texture_draw_bg(&bkgd, NO_UPDATE);
+ texture_draw_bg(&bkgd);
text_drawf(&blue_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
text_draw(&blue_text, "Your score:", 150, 180, 1, NO_UPDATE);
while(SDL_PollEvent(&event))
if(event.type == SDL_KEYDOWN)
- menu_event(&event.key.keysym);
+ menu_event(event);
- switch (menu_check(&highscore_menu))
+ switch (highscore_menu->check())
{
case 0:
- if(highscore_menu.item[0].input != NULL)
- strcpy(hs_name, highscore_menu.item[0].input);
+ if(highscore_menu->item[0].input != NULL)
+ strcpy(hs_name, highscore_menu->item[0].input);
break;
}
/* Try to open file: */
- fi = opendata("w");
+ fi = opendata(highscore_filename, "w");
if (fi != NULL)
{
fprintf(fi, "# Supertux highscore file\n\n");