Skip to content

Instantly share code, notes, and snippets.

@KimiTang
Created December 7, 2012 07:23
Show Gist options
  • Save KimiTang/4231465 to your computer and use it in GitHub Desktop.
Save KimiTang/4231465 to your computer and use it in GitHub Desktop.
ShenWei
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
//robot.turn(30);
robot.clone();
var xmove=1000;
if((robot.position.x>robot.arenaWidth-25||
robot.position.x<25||
robot.position.y>robot.arenaHeight-25||
robot.position.y<25)){
xmove=100;
}
if(robot.parentId=='element1'){
robot.turn(180);
robot.ahead(xmove);
}
else{
robot.ahead(xmove);
}
robot.rotateCannon(360);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scanned =ev.scannedRobot;
if(scanned.id !== robot.parentId && scanned.parentId !== robot.id) {
robot.rotateCannon(3);
robot.fire(5);
robot.ahead(100);
}
else{
robot.rotateCannon(30);
robot.ahead(50);
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(90+ev.bearing); // turn enought to be in a straight
// angle with the wall.
if((robot.position.x>robot.arenaWidth-25||
robot.position.x<25||
robot.position.y>robot.arenaHeight-25||
robot.position.y<25)&&ev.bearing==0){
robot.rotateCannon(-1*(99+ev.bearing));
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.ahead(50);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment