| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 508 人关注过本帖
标题:这是跟着书上写的一段代,第二排我没看懂,求讲解
只看楼主 加入收藏
Arise
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2012-12-2
结帖率:60%
收藏
 问题点数:0 回复次数:2 
这是跟着书上写的一段代,第二排我没看懂,求讲解
#include <airobot/c/SimpleRobot.h>
void  printBotInformation();
int  n=0;
/**
 * 每个单位时间都会触发
 */
void onTick(struct TickAction* action)
{
    double  x1=30,y1=30;
    if(n==0)
    {
    moveTo(30,30);
        if(fabs(getX()-x1)<0.01&&fabs(getY()-y1)<0.01)
            n++;
    }
    if(n==1)
    {
        moveTo(400,30);
        if(fabs(getX()-400)<0.01&&fabs(getY()-30)<0.01)
            n++;
    }
    if(n==2)
    {
        moveTo(400,400);
        if(fabs(getX()-400)<0.01&&fabs(getY()-400)<0.01)
            n++;
    }
    if(n==3)
        n=0;
    printBotInformation();
}
void  printBotInformation()
{
int selfId=getSelf();
struct  Bot* selfBot=getBot(selfId);//机器人坐标
printSD("x:",selfBot->x);
printSD("y:",selfBot->y);
//机器人方向
printSD("heading  by  degree:",selfBot->heading*180.0/PI);
//机器人速度
printSD("velocity:",selfBot->velocity);
}
 
/**
 * 当开始一场新的比赛时触发
 */
void onMatchBegin(struct MatchBeginAction* action){}
/**
 * 当整场比赛结束时触发
 */
void onMatchFinish(struct MatchFinishAction* action){}
/**
 * 当开始一轮新的比赛时触发
 */
void onRoundBegin(struct RoundBeginAction* action)
{
n=0;
}
/**
 * 当一轮比赛结束时触发。
 */
void onRoundFinish(struct RoundFinishAction* action){}

/**
 * 当有队友向自己发送消息时触发
 */
void onMessageReceived(struct MessageReceivedAction* action){}
/**
 * 当撞到其它机器人时触发
 */
void onHitRobot(struct HitRobotAction* action)
{}
/**
 * 当撞到墙时触发
 */
void onHitWall(struct HitWallAction* action)
{}
/**
 * 当任意一个机器人开火时触发
 */
void onFire(struct FireAction* action){}
/**
 * 当有机器人死亡时触发
 */
void onRobotDeath(struct RobotDeathAction* action){}
/**
 * 当自己的子弹击中敌人时触发
 */
void onBulletHit(struct BulletHitAction* action){}
/**
 * 当被别人的子弹击中时触发
 */
void onHitedByBullet(struct HitedByBulletAction* action){}


/**
 * 机器人程序入口
 */
int main(int argC, char* argV[])
{
    tickHook = onTick;
    matchBeginHook = onMatchBegin;
    matchFinishHook = onMatchFinish;
    roundBeginHook = onRoundBegin;
    roundFinishHook = onRoundFinish;
    messageReceivedHook = onMessageReceived;
    hitRobotHook = onHitRobot;
    hitWallHook = onHitWall;
    robotDeathHook = onRobotDeath;
    fireHook = onFire;
    bulletHitHook = onBulletHit;
    hitedByBulletHook = onHitedByBullet;
   
    return startup(argC, argV);
}
搜索更多相关主题的帖子: include double action 
2013-06-27 11:52
魔道无敌
Rank: 1
等 级:新手上路
帖 子:19
专家分:7
注 册:2013-2-27
收藏
得分:0 
函数声明,因为子函数写在主函数后面。
2013-06-28 22:57
love云彩
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:青藏高原
等 级:贵宾
威 望:53
帖 子:3663
专家分:11416
注 册:2012-11-17
收藏
得分:0 
不知道楼主指哪些代码?标注颜色吧

思考赐予新生,时间在于定义
2013-06-29 13:29
快速回复:这是跟着书上写的一段代,第二排我没看懂,求讲解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011382 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved