annotate lamertetris/sources/hiscore.C @ 3:84e66ea83026

DPF-Prymula-audioplugins-0.231015-2
author prymula <prymula76@outlook.com>
date Mon, 16 Oct 2023 21:53:34 +0200
parents 2787f5e749ae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
prymula <prymula76@outlook.com>
parents:
diff changeset
1 #if WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
2 #include "hiscore_win.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
3 #elif LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
4 #include "hiscore_linux.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
5 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
6
prymula <prymula76@outlook.com>
parents:
diff changeset
7 HiScore::HiScore() {
prymula <prymula76@outlook.com>
parents:
diff changeset
8 }
prymula <prymula76@outlook.com>
parents:
diff changeset
9
prymula <prymula76@outlook.com>
parents:
diff changeset
10 HiScore::~HiScore() {
prymula <prymula76@outlook.com>
parents:
diff changeset
11 }
prymula <prymula76@outlook.com>
parents:
diff changeset
12
prymula <prymula76@outlook.com>
parents:
diff changeset
13 SDL_bool HiScore::file_exist(){
prymula <prymula76@outlook.com>
parents:
diff changeset
14 char *file;
prymula <prymula76@outlook.com>
parents:
diff changeset
15
prymula <prymula76@outlook.com>
parents:
diff changeset
16
prymula <prymula76@outlook.com>
parents:
diff changeset
17 if (!getenv(HOME.c_str())) goto skip2;
prymula <prymula76@outlook.com>
parents:
diff changeset
18
prymula <prymula76@outlook.com>
parents:
diff changeset
19 file=(char *)malloc(strlen(getenv(HOME.c_str()))+strlen(FILE_NAME.c_str())+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
20
prymula <prymula76@outlook.com>
parents:
diff changeset
21 strcpy(file, getenv(HOME.c_str()));
prymula <prymula76@outlook.com>
parents:
diff changeset
22 strcat(file, FILE_NAME.c_str());
prymula <prymula76@outlook.com>
parents:
diff changeset
23 printf("1");
prymula <prymula76@outlook.com>
parents:
diff changeset
24
prymula <prymula76@outlook.com>
parents:
diff changeset
25 if (access(file, F_OK)==0){
prymula <prymula76@outlook.com>
parents:
diff changeset
26 printf("PLIK istnieje %s",file);
prymula <prymula76@outlook.com>
parents:
diff changeset
27 free(file);
prymula <prymula76@outlook.com>
parents:
diff changeset
28 return SDL_TRUE;
prymula <prymula76@outlook.com>
parents:
diff changeset
29 }
prymula <prymula76@outlook.com>
parents:
diff changeset
30 printf("PLIK nie istnieje %s",file);
prymula <prymula76@outlook.com>
parents:
diff changeset
31 free(file);
prymula <prymula76@outlook.com>
parents:
diff changeset
32 skip2:
prymula <prymula76@outlook.com>
parents:
diff changeset
33 return SDL_FALSE;
prymula <prymula76@outlook.com>
parents:
diff changeset
34
prymula <prymula76@outlook.com>
parents:
diff changeset
35
prymula <prymula76@outlook.com>
parents:
diff changeset
36 }
prymula <prymula76@outlook.com>
parents:
diff changeset
37
prymula <prymula76@outlook.com>
parents:
diff changeset
38 void HiScore::save_hiscore(int hiscore){
prymula <prymula76@outlook.com>
parents:
diff changeset
39
prymula <prymula76@outlook.com>
parents:
diff changeset
40 char *file;
prymula <prymula76@outlook.com>
parents:
diff changeset
41 char bufor[128];
prymula <prymula76@outlook.com>
parents:
diff changeset
42 if (getenv(HOME.c_str())) {
prymula <prymula76@outlook.com>
parents:
diff changeset
43
prymula <prymula76@outlook.com>
parents:
diff changeset
44 file=(char *)malloc(strlen(getenv(HOME.c_str()))+strlen(FILE_NAME.c_str())+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
45
prymula <prymula76@outlook.com>
parents:
diff changeset
46 strcpy(file, getenv(HOME.c_str()));
prymula <prymula76@outlook.com>
parents:
diff changeset
47 strcat(file, FILE_NAME.c_str());
prymula <prymula76@outlook.com>
parents:
diff changeset
48
prymula <prymula76@outlook.com>
parents:
diff changeset
49 sprintf(bufor,"%d",hiscore);
prymula <prymula76@outlook.com>
parents:
diff changeset
50
prymula <prymula76@outlook.com>
parents:
diff changeset
51 FILE * f = fopen(file, "w");
prymula <prymula76@outlook.com>
parents:
diff changeset
52 fwrite(bufor, sizeof(char), strlen(bufor), f);
prymula <prymula76@outlook.com>
parents:
diff changeset
53 fclose(f);
prymula <prymula76@outlook.com>
parents:
diff changeset
54 printf ("ZapisaƂem: %s\n", file);
prymula <prymula76@outlook.com>
parents:
diff changeset
55 free(file);
prymula <prymula76@outlook.com>
parents:
diff changeset
56 }
prymula <prymula76@outlook.com>
parents:
diff changeset
57 }
prymula <prymula76@outlook.com>
parents:
diff changeset
58
prymula <prymula76@outlook.com>
parents:
diff changeset
59 int HiScore::load_hiscore(){
prymula <prymula76@outlook.com>
parents:
diff changeset
60
prymula <prymula76@outlook.com>
parents:
diff changeset
61 char *file;
prymula <prymula76@outlook.com>
parents:
diff changeset
62 char bufor[128];
prymula <prymula76@outlook.com>
parents:
diff changeset
63 if (!getenv(HOME.c_str())) exit(1);
prymula <prymula76@outlook.com>
parents:
diff changeset
64
prymula <prymula76@outlook.com>
parents:
diff changeset
65 file=(char *)malloc(strlen(getenv(HOME.c_str()))+strlen(FILE_NAME.c_str())+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
66
prymula <prymula76@outlook.com>
parents:
diff changeset
67 strcpy(file, getenv(HOME.c_str()));
prymula <prymula76@outlook.com>
parents:
diff changeset
68 strcat(file, FILE_NAME.c_str());
prymula <prymula76@outlook.com>
parents:
diff changeset
69
prymula <prymula76@outlook.com>
parents:
diff changeset
70 FILE * f = fopen(file, "r");
prymula <prymula76@outlook.com>
parents:
diff changeset
71 fscanf(f, "%s", bufor);
prymula <prymula76@outlook.com>
parents:
diff changeset
72 fclose(f);
prymula <prymula76@outlook.com>
parents:
diff changeset
73 free(file);
prymula <prymula76@outlook.com>
parents:
diff changeset
74
prymula <prymula76@outlook.com>
parents:
diff changeset
75 return atoi(bufor);
prymula <prymula76@outlook.com>
parents:
diff changeset
76
prymula <prymula76@outlook.com>
parents:
diff changeset
77 }