资源简介

此贪吃蛇小游戏用c语言编写,链表实现,图形界面基于curses库实现,界面有计时器,还可以实时记录分数,显示当前分数,上一次游戏分数,历史游戏最高分数。

资源截图

代码片段和文件信息


#include“main.h“
#include
#define LAST_SCORE_FILE “./last_score.txt“
#define HIGHEST_SCORE_FILE “./highest_score.txt“




void Write_data(int scoreint write_file)
{

if(write_file==1)
{
FILE *fpWrite1=fopen(LAST_SCORE_FILE“w“);
fprintf(fpWrite1“%d\n“score);
fclose(fpWrite1);
}
if(write_file==2)
{
FILE *fpWrite2=fopen(HIGHEST_SCORE_FILE“w“);
fprintf(fpWrite2“%d\n“score);
fclose(fpWrite2);
}

}

int Read_data(int read_file)
{
if (read_file==1)
{
int last_score;
FILE *fpRead=fopen(LAST_SCORE_FILE“r“);
fscanf(fpRead“%d“&last_score);
fclose(fpRead);
return last_score;
}
if (read_file==2)
{
int highest_score;
FILE *fpRead=fopen(HIGHEST_SCORE_FILE“r“);
fscanf(fpRead“%d“&highest_score);
fclose(fpRead);
return highest_score;
}

}




int Compare(int current_score)
{
highest_score=Read_data(2);
if(highest_score<=current_score)
{
highest_score=current_score;
Write_data(highest_score2);
}
return highest_score;
}



评论

共有 条评论