Mercurial > hg > pub > prymula > com
diff lamertetris/sources/hiscore.C @ 0:2787f5e749ae
INIT
author | prymula <prymula76@outlook.com> |
---|---|
date | Thu, 21 Sep 2023 22:33:57 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lamertetris/sources/hiscore.C Thu Sep 21 22:33:57 2023 +0200 @@ -0,0 +1,77 @@ +#if WINDOWS + #include "hiscore_win.h" +#elif LINUX + #include "hiscore_linux.h" +#endif + +HiScore::HiScore() { +} + +HiScore::~HiScore() { +} + +SDL_bool HiScore::file_exist(){ + char *file; + + + if (!getenv(HOME.c_str())) goto skip2; + + file=(char *)malloc(strlen(getenv(HOME.c_str()))+strlen(FILE_NAME.c_str())+1); + + strcpy(file, getenv(HOME.c_str())); + strcat(file, FILE_NAME.c_str()); + printf("1"); + + if (access(file, F_OK)==0){ + printf("PLIK istnieje %s",file); + free(file); + return SDL_TRUE; + } + printf("PLIK nie istnieje %s",file); + free(file); +skip2: + return SDL_FALSE; + + +} + +void HiScore::save_hiscore(int hiscore){ + + char *file; + char bufor[128]; + if (getenv(HOME.c_str())) { + + file=(char *)malloc(strlen(getenv(HOME.c_str()))+strlen(FILE_NAME.c_str())+1); + + strcpy(file, getenv(HOME.c_str())); + strcat(file, FILE_NAME.c_str()); + + sprintf(bufor,"%d",hiscore); + + FILE * f = fopen(file, "w"); + fwrite(bufor, sizeof(char), strlen(bufor), f); + fclose(f); + printf ("ZapisaĆem: %s\n", file); + free(file); + } +} + +int HiScore::load_hiscore(){ + + char *file; + char bufor[128]; + if (!getenv(HOME.c_str())) exit(1); + + file=(char *)malloc(strlen(getenv(HOME.c_str()))+strlen(FILE_NAME.c_str())+1); + + strcpy(file, getenv(HOME.c_str())); + strcat(file, FILE_NAME.c_str()); + + FILE * f = fopen(file, "r"); + fscanf(f, "%s", bufor); + fclose(f); + free(file); + + return atoi(bufor); + +}