view lamertetris/sources/hiscore.C @ 15:f61684ae8245

READEM FIX
author prymula <prymula76@outlook.com>
date Sat, 10 Feb 2024 21:05:36 +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);

}