Skip to content

Instantly share code, notes, and snippets.

@AndreMeira
Forked from joseleme/robot.js
Created December 3, 2012 15:35
Show Gist options
  • Save AndreMeira/4195760 to your computer and use it in GitHub Desktop.
Save AndreMeira/4195760 to your computer and use it in GitHub Desktop.
Dummy goes
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot){
robot.turn(45);
robot.clone();
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
for (var i=0; i<5; i++) {
robot.ahead(50);
robot.turn(90);
}
};
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);
}
for (var i=0; i<5; i++) {
robot.fire();
robot.turn(2);
}
};
Robot.prototype.onWallCollision = function(ev) {
//ev.robot.stop();
ev.robot.turn(ev.bearing);
ev.robot.back(150);
//robot.direction = -robot.direction;
};
Robot.prototype.onRobotCollided = function(ev) {
//ev.robot.stop();
ev.robot.back(100);
ev.robot.turn(20);
ev.robot.ahead(100);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment