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

📄 filer.c

📁 偶然收集到的一个C语言源码
💻 C
字号:
#include <airobot/c/SimpleRobot.h>
	
/* 这是一个演示读写文件的机器人。
 * 在比赛开始时,机器人读取自己上一场比赛的得分信息,显示在控制台上。
 * 在比赛结束时,机器人将自己的得分信息保存到文件中。
 */
/**
 * 每个单位时间都会触发
 */
void onTick(struct TickAction* action)
{
	struct Bot* opponent = getFirstOpponent();
	if(opponent==NULL) return;
	fireOnPoint(opponent->x, opponent->y, 2);
}
/** 
 * 当开始一场新的比赛时触发
 */
void onMatchBegin(struct MatchBeginAction* action)
{
	FILE *fp;
  	double score;
	if((fp=fopen("filer","r"))!=NULL)
  	{
		fscanf(fp, "%lf", &score);
		fclose(fp);
		printSD("The last match score is : ", score);
	}
	else println("Can not read the last match record.");
}

/**
 * 当整场比赛结束时触发
 */
void onMatchFinish(struct MatchFinishAction* action)
{
	FILE *fp;
	if((fp=fopen("filer","w"))!=NULL)
  	{
		fprintf(fp, "%lf", getScore());
		fclose(fp);
	}
	else println("Can not save the match record.");
}

/**
 * 机器人程序入口
 */
int main(int argC, char* argV[])
{
	tickHook = onTick;
	matchBeginHook = onMatchBegin;
	matchFinishHook = onMatchFinish;	
	return startup(argC, argV);
}

																	

⌨️ 快捷键说明

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