Mercurial > hg > pub > prymula > com
view lamertetris/sources/hiscore.C @ 24:c7e131ce2f14
makefile rm
author | Przemyslaw <prymula76@outlook.com> |
---|---|
date | Mon, 01 Apr 2024 07:16:40 +0200 |
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); }