Skip to content

Instantly share code, notes, and snippets.

@jpospychala
Created December 6, 2012 09:29
Show Gist options
  • Select an option

  • Save jpospychala/4223229 to your computer and use it in GitHub Desktop.

Select an option

Save jpospychala/4223229 to your computer and use it in GitHub Desktop.

Revisions

  1. jpospychala created this gist Dec 6, 2012.
    34 changes: 34 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@

    //FightCode can only understand your robot
    //if its class is called Robot
    var Robot = function(robot) {
    this.sgn = 1;
    this.count = 0;
    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(10);
    robot.rotateCannon(-10);
    //robot.back(100);
    //robot.rotateCannon(360);

    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    robot.fire();
    robot.rotateCannon(robot.sgn*-10);
    robot.turn(robot.sgn*10);
    robot.count = (robot.count + 1) % 2;
    if (robot.count == 0) {
    robot.sgn *= -1;
    }
    };

    Robot.prototype.onWallCollision = function(ev) {
    var r = ev.robot;
    r.rotateCannon(-30);
    r.turn(30);
    }