📄 bridge.c
字号:
#include "Bridge.h"
#include "Robot.h"
//////////////////////////////////////////////////////////////
//robot
void __cdecl localWork()
{
work();
}
//事件处理函数,相应事件发生时被调用一次
/*
* 当雷达扫描到敌人时触发
*/
void __cdecl localOnScannedRobot(
long t, const char * n, double x,
double y, double h, double v, double e )
{
scannedRobotEvent.time = t;
scannedRobotEvent.name = n;
scannedRobotEvent.x = x;
scannedRobotEvent.y = y;
scannedRobotEvent.heading = h;
scannedRobotEvent.velocity = v;
scannedRobotEvent.energy = e;
onScannedRobot();
}
/*
* 当打中某个敌人时触发
*/
void __cdecl localOnBulletHit(
long t, double p, const char* n, double x, double y)
{
bulletHitEvent.time = t;
bulletHitEvent.power = p;
bulletHitEvent.name = n;
bulletHitEvent.x = x;
bulletHitEvent.y = y;
onBulletHit();
}
/*
* 当被敌人打中时触发
*/
void __cdecl localOnHitByBullet(long t, const char * n, double p)
{
hitByBulletEvent.time = t;
hitByBulletEvent.name = n;
hitByBulletEvent.power = p;
onHitByBullet();
}
/*
* 当撞到其它敌人时触发
*/
void __cdecl localOnHitRobot(long t, const char * n, double x, double y)
{
hitRobotEvent.time = t;
hitRobotEvent.name = n;
hitRobotEvent.x = x;
hitRobotEvent.y = y;
onHitRobot();
}
/*
* 当某个敌人死时触发
*/
void __cdecl localOnRobotDeath(long t, const char * n)
{
robotDeathEvent.time = t;
robotDeathEvent.name = n;
onRobotDeath();
}
/*
* 当撞到墙时触发
*/
void __cdecl localOnHitWall(long t)
{
hitWallEvent.time = t;
onHitWall();
}
/*
* 当开始一轮新的战斗时触发
*/
void __cdecl localOnBegin(long t)
{
beginEvent.time = t;
onBegin();
}
/*
* 当一轮战斗结束时触发
*/
void __cdecl localOnFinish(long t)
{
finishEvent.time = t;
onFinish();
}
/*
* 当机器人执行操作超时时触发
*/
void __cdecl localOnOvertime(long t)
{
overtimeEvent.time = t;
onOvertime();
}
////////////////////////////////////////////////////////////////////
// 这些函数由系统调用,设置一些关于机器人当前状态的信息/*
/*
* 设置当前时间
*/
void __cdecl localSetTime(long t)
{
setTime(t);
}
/*
* 设置当前的比赛轮数
*/
void __cdecl localSetCurrentRound(int r)
{
setCurrentRound(r);
}
/*
* 设置总的比赛轮数
*/
void __cdecl localSetTotalRounds(int t)
{
setTotalRounds(t);
}
/*
* 设置剩余能量
*/
void __cdecl localSetEnergy(double e)
{
setEnergy(e);
}
/*
* 设置当前的比赛得分
*/
void __cdecl localSetScore(double s)
{
setScore(s);
}
/*
* 设置当前敌人总数
*/
void __cdecl localSetOthers(int o)
{
setOthers(o);
}
/**
* 设置地图
*/
void __cdecl localSetMap(int w, int h)
{
map.height = w;
map.width = h;
}
/**
* 得到当前输出
*/
char * __cdecl localGetOutput()
{
return getOutput();
}
////////////////////////////////////////////////////////////////////////////
//body
/*
* 得到用户想用转动的角度的剩余量
* 比如:上个单位时间,用户用turn(Math.toRadians(15))让车身旋转15度
* 但是车身的最大旋转速度为10度/单位时间,所以这个单位时间调用getTurnRemaining()
* 会得到返回值0.08754(5/180*PI),说明还有5度需要转动,如果用户此时没有新的turn函数的调用
* 那么下个单位时间车身将会只转动5度
*/
double __cdecl localGetBodyTurnRemaining()
{
return getBodyTurnRemaining();
}
/*
* 得到用户想要到达的速度
*/
double __cdecl localGetBodyPreferVelocity()
{
return getBodyPreferVelocity();
}
// 这些函数由系统调用,设置一些关于机器人当前状态的信息
/*
* 设置当前的坐标
*/
void __cdecl localSetBodyPosition(double x, double y)
{
setBodyPosition(x,y);
}
/*
* 设置当前的车身方向
*/
void __cdecl localSetBodyHeading(double h)
{
setBodyHeading(h);
}
/*
* 设置当前的移动速度
*/
void __cdecl localSetBodyVelocity(double v)
{
setBodyVelocity(v);
}
//////////////////////////////////////////////////////////////////////
//gun
// 得到用户想用转动的度数的剩余量
double __cdecl localGetGunTurnRemaining()
{
return getGunTurnRemaining();
}
// 得到用户将要发射的炮弹的能量
double __cdecl localGetFirePower()
{
return getFirePower();
}
// 设置当前方向
void __cdecl localSetGunHeading(double h)
{
setGunHeading(h);
}
// 设置发单的准备时间
void __cdecl localSetGunPrepareTime(long t)
{
setGunPrepareTime(t);
}
////////////////////////////////////////////////////////////////////////
//radar
/*
* 得到用户想用转动的角度的剩余量
* 比如:上个单位时间,用户用turn(Math.toRadians(50))让雷达旋转50度
* 但是雷达的最大旋转速度为45度/单位时间,所以这个单位时间调用getTurnRemaining()
* 会得到返回值0.08754(5/180*PI),说明还有5度需要转动,如果用户此时没有新的turn函数的调用
* 那么下个单位时间雷达将会只转动5度
*/
double __cdecl localGetRadarTurnRemaining()
{
return getRadarTurnRemaining();
}
/*
* 设置当前方向
*/
void __cdecl localSetRadarHeading(double heading)
{
setRadarHeading(heading);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -