0
|
1 #if WINDOWS
|
|
2 #include "hiscore_win.h"
|
|
3 #elif LINUX
|
|
4 #include "hiscore_linux.h"
|
|
5 #endif
|
|
6
|
|
7 HiScore::HiScore() {
|
|
8 }
|
|
9
|
|
10 HiScore::~HiScore() {
|
|
11 }
|
|
12
|
|
13 SDL_bool HiScore::file_exist(){
|
|
14 char *file;
|
|
15
|
|
16
|
|
17 if (!getenv(HOME.c_str())) goto skip2;
|
|
18
|
|
19 file=(char *)malloc(strlen(getenv(HOME.c_str()))+strlen(FILE_NAME.c_str())+1);
|
|
20
|
|
21 strcpy(file, getenv(HOME.c_str()));
|
|
22 strcat(file, FILE_NAME.c_str());
|
|
23 printf("1");
|
|
24
|
|
25 if (access(file, F_OK)==0){
|
|
26 printf("PLIK istnieje %s",file);
|
|
27 free(file);
|
|
28 return SDL_TRUE;
|
|
29 }
|
|
30 printf("PLIK nie istnieje %s",file);
|
|
31 free(file);
|
|
32 skip2:
|
|
33 return SDL_FALSE;
|
|
34
|
|
35
|
|
36 }
|
|
37
|
|
38 void HiScore::save_hiscore(int hiscore){
|
|
39
|
|
40 char *file;
|
|
41 char bufor[128];
|
|
42 if (getenv(HOME.c_str())) {
|
|
43
|
|
44 file=(char *)malloc(strlen(getenv(HOME.c_str()))+strlen(FILE_NAME.c_str())+1);
|
|
45
|
|
46 strcpy(file, getenv(HOME.c_str()));
|
|
47 strcat(file, FILE_NAME.c_str());
|
|
48
|
|
49 sprintf(bufor,"%d",hiscore);
|
|
50
|
|
51 FILE * f = fopen(file, "w");
|
|
52 fwrite(bufor, sizeof(char), strlen(bufor), f);
|
|
53 fclose(f);
|
|
54 printf ("ZapisaĆem: %s\n", file);
|
|
55 free(file);
|
|
56 }
|
|
57 }
|
|
58
|
|
59 int HiScore::load_hiscore(){
|
|
60
|
|
61 char *file;
|
|
62 char bufor[128];
|
|
63 if (!getenv(HOME.c_str())) exit(1);
|
|
64
|
|
65 file=(char *)malloc(strlen(getenv(HOME.c_str()))+strlen(FILE_NAME.c_str())+1);
|
|
66
|
|
67 strcpy(file, getenv(HOME.c_str()));
|
|
68 strcat(file, FILE_NAME.c_str());
|
|
69
|
|
70 FILE * f = fopen(file, "r");
|
|
71 fscanf(f, "%s", bufor);
|
|
72 fclose(f);
|
|
73 free(file);
|
|
74
|
|
75 return atoi(bufor);
|
|
76
|
|
77 }
|