⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hiscore.c

📁 C大程序 需要解压
💻 C
字号:
#define SCORE_X0 20
#define SCORE_Y0 57
#define SCORE_X1 100
#define SCORE_Y1 72

#define HISCORE_LIST_X 130
#define HISCORE_LIST_Y 12

#define HISCORE_NEW_X 120
#define HISCORE_NEW_Y 65

#define HISCORE_GET_X 120
#define HISCORE_GET_Y 65

#define HISCORE_EDIT_X 137
#define HISCORE_EDIT_Y 88

#define HISCORE_ENCOUNT 7

bmp_picture num;

long score = 0;

typedef struct hiscore_typ{
	unsigned char name[13];
	long score;
}hiscore;

hiscore hi[10];

char hiscore_equalname[HISCORE_ENCOUNT][2][13] = {{"YANGCHENXING", "杨晨醒"}, {"XUJIA", "徐家"}, {"GAOCHENGXING", "高承星"}, {"SHITIANJIAO", "施天骄"}, {"RONGYUJIE", "荣钰杰"}, {"NONAME", "匿名"}, {"ZHANGYIN", "张引"}};

void hiscore_load(){
	int i;
	FILE *fs;

	if ((fs = fopen("hiscore.txt", "r")) == NULL){
		printf("Can't open hiscore.txt\n");
		getch();
		exit(1);
	}
	for (i = 0; i < 10; i++)
		fscanf(fs, "%s %ld", hi[i].name, &hi[i].score);
	fclose(fs);
}

void hiscore_save(){
	int i;
	FILE *fs;

	if ((fs = fopen("hiscore.txt", "w")) == NULL){
		printf("Can't open hiscore.txt\n");
		getch();
		exit(1);
	}
	for (i = 0; i < 10; i++)
		fprintf(fs, "%s %ld\n", hi[i].name, hi[i].score);
	fclose(fs);
}

void digit_out(int x, int y, int d){
	int i, j;

	for (i = 15, j = 0; i >= 0; i--, j++)
		_fmemcpy(&video_buffer[(y + i) * SCREEN_WIDTH + x], &num.buffer[j * 80 + d * 8], 8);
}

void score_out(){
	long i, j, k, temp;
	int digit[10];
	int x, y;

	temp = score;
	k = -1;
	do{
		digit[++k] = temp % 10;
		temp /= 10;
	}while (temp);
	x = (SCORE_X1 + SCORE_X0) / 2 - 8 * (k + 1) / 2;
	y = SCORE_Y0;
	for (i = k, j = 0; i >= 0; i--, j++)
		digit_out(x + j * 8, y, digit[i]);
}

void score_init(){
	BMP_Load("num_0.bmp", &num);
}

void hiscore_show(){
	int i;
	char temp[10];

	hiscore_load();
	mouse_putback();
	clean_black(120, 0, 200, 200);
	alpha_put_string("NAME", HISCORE_LIST_X, HISCORE_LIST_Y);
	alpha_put_string("SCORE", HISCORE_LIST_X + 96 + 20, HISCORE_LIST_Y);
	for (i = 0; i < 10; i++){
//		alpha_put_string(hi[i].name, HISCORE_LIST_X, HISCORE_LIST_Y + (i + 1) * 15);
		hz_put_mix(hi[i].name, HISCORE_LIST_X, HISCORE_LIST_Y + (i + 1) * 16);
		alpha_put_string(ltoa(hi[i].score, temp, 10), HISCORE_LIST_X + 96 + 20, HISCORE_LIST_Y + (i + 1) * 16);
	}
	mouse_get();
	mouse_getback();
	mouse_showcur();
	mouse_wait();
	clean_black(120, 0, 200, 200);
	diamond_showall();
}

int hiscore_newhiscore(){
	int i;

	hiscore_load();
	for (i = 0; i < 10; i++)
		if (hi[i].score <= score) return 1;
	return 0;
}

void hiscore_newhiscore_show(){
	mouse_putback();
	BMP_DirectShow("hiscore0.bmp", HISCORE_NEW_X, HISCORE_NEW_Y);
	mouse_get();
	mouse_getback();
	mouse_showcur();
	mouse_wait();
	clean_black(120, 0, 200, 200);
	diamond_showall();
}

void hiscore_changename(char *name){
	int i;
	char temp[13];

	strcpy(temp, name);
	for (i = 0; temp[i]; i++) if (islower(temp[i])) temp[i] -= 32;
	for (i = 0; i < HISCORE_ENCOUNT; i++)
		if (!strcmp(temp, hiscore_equalname[i][0])){
			strcpy(name, hiscore_equalname[i][1]);
			return;
		}
}

void hiscore_newhiscore_getname(char *name){
	int key, len = 0;

	mouse_putback();
	BMP_DirectShow("hiscores.bmp", HISCORE_GET_X, HISCORE_GET_Y);
	mouse_get();
	mouse_getback();
	mouse_showcur();
	name[0] = 0;
	do{
		do{
			mouse_get();
			if (mouse_move) mouse_fresh();
			sound_gdserver();
		}while (!kbhit());
		mouse_putback();
		key = getch();
		if ((key > 32) && (key <= 126) && (len < 12)){
			alpha_put(key, HISCORE_EDIT_X + (len + 1) * 8, HISCORE_EDIT_Y);
			name[len++] = key;
			name[len] = 0;
		} else
		if (key == 8){
			name[--len] = 0;
			alpha_put(32, HISCORE_EDIT_X + (len + 1) * 8, HISCORE_EDIT_Y);
		}
		mouse_get();
		mouse_getback();
		mouse_showcur();
	}while (key != 13);
	clean_black(120, 0, 200, 200);
	diamond_showall();
	if (name[0] == 0) strcpy(name, "noname");
	hiscore_changename(name);
}

void hiscore_insert(const char name[13]){
	char temp_name[13], change_name[13];
	long temp_score, change_score;
	int i;

	hiscore_load();
	strcpy(temp_name, name);
	temp_score = score;
	for (i = 0; i < 10; i++)
		if (temp_score >= hi[i].score){
			strcpy(change_name, hi[i].name);
			change_score = hi[i].score;
			strcpy(hi[i].name, temp_name);
			hi[i].score = temp_score;
			strcpy(temp_name, change_name);
			temp_score = change_score;
		}
	hiscore_save();
}

void hiscore_savehiscore(){
	char name[13];

	hiscore_newhiscore_show();
	hiscore_newhiscore_getname(name);
	hiscore_insert(name);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -