Skip to content

Instantly share code, notes, and snippets.

@dudadornelles
Forked from marano/robot.js
Created December 6, 2012 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dudadornelles/4221822 to your computer and use it in GitHub Desktop.
Save dudadornelles/4221822 to your computer and use it in GitHub Desktop.
Shrimp Hunter
var RobotState = function () {
data = {};
data.isLookingAtTarget = false;
return data;
};
var goodRobot = RobotState();
var evilRobot = RobotState();
var clonedEvilMe = false;
//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;
if (robot.parentId == null) {
if (!clonedEvilMe) {
robot.clone();
clonedEvilMe = true;
}
if (!goodRobot.isLookingAtTarget) {
robot.turn(1);
goodRobot.isLookingAtTarget = false;
}
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
if (ev.parentId == null) {
goodRobot.isLookingAtTarget = true;
robot.fire();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment