-
-
Save glauberramos/4224315 to your computer and use it in GitHub Desktop.
Shrimp Hunter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var aVera = true; | |
var Robot = function(robot) {}; | |
var RobotState = function (rotateStep) { | |
data = {}; | |
data.id = 0; | |
data.isLookingAtTarget = false; | |
data.timesShooting = 0; | |
data.rotateStep = rotateStep; | |
return data; | |
}; | |
var goodRobot = RobotState(1); | |
var evilRobot = RobotState(-1); | |
var clonedEvilMe = false; | |
var currentRobotData = function (robot) { | |
if (robot.parentId == null) { | |
return goodRobot; | |
} else { | |
return evilRobot; | |
} | |
}; | |
var robotOnIdle = function (robot) { | |
var robotData = currentRobotData(robot); | |
if (robotData.isLookingAtTarget) { | |
if (robotData.timesShooting <= 5) { | |
if (robot.gunCoolDownTime == 0) { | |
robotData.timesShooting = robotData.timesShooting + 1; | |
robot.fire(); | |
} | |
} else { | |
robotData.timesShooting = 0; | |
robotData.isLookingAtTarget = false; | |
} | |
} else { | |
robot.turn(robotData.rotateStep); | |
} | |
}; | |
var robotOnScannedRobot = function (robot, scannedRobot) { | |
var robotData = currentRobotData(robot); | |
if (aVera) { | |
if (scannedRobot.id != goodRobot.id && scannedRobot.parentId != goodRobot.id) { | |
robotData.isLookingAtTarget = true; | |
} | |
} else { | |
robotData.isLookingAtTarget = true; | |
} | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if (robot.parentId == null) { | |
if (!clonedEvilMe) { | |
goodRobot.id = robot.id; | |
robot.clone(); | |
clonedEvilMe = true; | |
} | |
} | |
robotOnIdle(robot); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
robotOnScannedRobot(ev.robot, ev.scannedRobot); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment