Created
January 5, 2014 16:59
-
-
Save dchaplinsky/8270732 to your computer and use it in GitHub Desktop.
guess what
This file contains hidden or 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
| /* | |
| * Open all three doors to exit. | |
| * | |
| * The answer is 5. | |
| */ | |
| var stop = function(self) { | |
| self.thrusters.top(false); | |
| self.thrusters.left(false); | |
| self.thrusters.bottom(false); | |
| self.thrusters.right(false); | |
| } | |
| this.on("start", function() { | |
| this.thrusters.left(true); | |
| this.radar.angle(0); | |
| this.radar.ping(); | |
| }); | |
| this.on("radar:hit", function(angle, distance) { | |
| console.log(distance); | |
| if (angle == 0) { | |
| if (Math.abs(distance - 370) < 10) { | |
| stop(this); | |
| this.thrusters.bottom(true); | |
| } else if (Math.abs(distance - 170) < 10) { | |
| stop(this); | |
| this.thrusters.top(true); | |
| this.radar.angle(90); | |
| this.radar.ping(); | |
| } else { | |
| this.radar.ping(); | |
| } | |
| } else if (angle == 90) { | |
| if (Math.abs(distance - 270) < 10) { | |
| this.thrusters.right(true); | |
| } else { | |
| this.radar.ping(); | |
| } | |
| } | |
| }); | |
| this.on("sensor:top", function(foo) { | |
| if (foo) { | |
| stop(this); | |
| this.thrusters.left(true); | |
| } else { | |
| this.radar.ping(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment