Skip to content

Instantly share code, notes, and snippets.

@spulec
Forked from heynemann/robot.js
Created December 1, 2012 02:21
Show Gist options
  • Save spulec/4180237 to your computer and use it in GitHub Desktop.
Save spulec/4180237 to your computer and use it in GitHub Desktop.
Back and Forth
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot){
robot.clone();
this.direction = 1;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (this.direction == 1) {
robot.ahead(5);
} else {
robot.back(5);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot, scannedRobot = ev.scannedRobot;
if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
return;
}
robot.stop();
for (var i=0; i<10; i++) {
robot.fire();
robot.ahead(10);
}
};
Robot.prototype.onWallCollision = function(ev) {
ev.robot.stop();
ev.robot.back(10);
ev.robot.rotateCannon(180);
};
Robot.prototype.onRobotCollision = function(ev) {
ev.robot.stop();
ev.robot.back(10);
ev.robot.rotateCannon(180);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment