[Home]Rebot

Robo Home | Changes | Preferences | AllPages

This is a robot that just comunicates whith a brains class. I plan to create severall inheriting classes from the brain class for different modes of battling. As you can see it is nowhere near being finished. --DB


package db; import robocode.*; import java.awt.Color; /**

 * Rebot - a robot by (Darrel)
 */
public class Rebot extends TeamRobot {
	Brains Logic = new Brains(this);
	public void run() {
		setColors(Color.black,Color.red,Color.orange);
		while(true) {
			turnRadarRight?(360);
			ahead(200);
		}
	}
	public void onScannedRobot(ScannedRobotEvent e) {
		Logic.onScannedRobot(e);
	}
	public void onHitByBullet?(HitByBulletEvent? e) {
		Logic.onHitByBullet?(e);
	}
	public void onHitWall?(HitWallEvent? e) {
		Logic.onHitWall?(e);
	}
	public void onHitRobot?(HitRobotEvent? e) {
		Logic.onHitRobot?(e);
	}
}


Here is the brains class

package db; import robocode.*;

/**

 * Brains - a class by (Darrel)
 */
public class Brains {
	Robot caller;
	public Brains(Robot robot)
	{
		caller = robot;
	}
	public void onScannedRobot(ScannedRobotEvent e) {
		caller.turnGunRight?(e.getBearing());
		if (e.getDistance()>100)
			caller.fire(2);
		else
			caller.fire(3);
		caller.scan();
		caller.turnGunLeft?(e.getBearing());
	}

	public void onHitByBullet?(HitByBulletEvent? e) {
		caller.turnRight(e.getBearing()+45);
		caller.ahead(100);
		caller.scan();
	}

	public void onHitWall?(HitWallEvent? e) {
		caller.turnRight(e.getBearing()+180);
	}

	public void onHitRobot?(HitRobotEvent? e) {
		caller.turnGunRight?(e.getBearing());
		for (double energy = e.getEnergy() ; energy > 0 ; energy = energy - 12)
			caller.fire(3);
		caller.turnGunLeft?(e.getBearing());
	}
} The Brains class should be way more simple, I admit, but here it is for right now.



Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited May 12, 2006 16:57 EST by DB (diff)
Search: