Mercurial > hg > pub > prymula > com
view lamertetris/sources/hiscore.C @ 10:4dc186728822
immposiblerush-0.230919-2
author | prymula <prymula76@outlook.com> |
---|---|
date | Sun, 04 Feb 2024 23:27:00 +0100 |
parents | 2787f5e749ae |
children |
line wrap: on
line source
#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); }