view lamertetris/sources/hiscore.C @ 21:bef3b1af6326

trix - package for arch
author Przemyslaw <prymula76@outlook.com>
date Sun, 31 Mar 2024 22:14:33 +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);

}