資源簡介
此貪吃蛇小游戲用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;
}
- 上一篇:如何用VC++創建及調用DLL
- 下一篇:利用C語言實現FFT的程序方法
評論
共有 條評論