Now, compile it by selecting '''Compile''' in the '''Compiler''' menu.

Now, compile it by selecting '''Compile''' in the '''Compiler''' menu.

−

If your robot compiles without any errors, you can start a new battle with your robot. Start a new battle by selecting '''New''' in the '''Battle''' menu. If you cannot see your robot, you might have to refresh the list of robots by pressing '''F5'''. Add your robot to the battle together with at least one other robot as e.g. sample.Target, and press the '''Start Battle''' button to let the games begin!

+

If your robot compiles without any errors, you can start a new battle with your robot. Start a new battle by selecting '''New''' in the '''Battle''' menu. If you cannot see your robot, you might have to refresh the list of robots by '''pressing F5'''. Add your robot to the battle together with at least one other robot as e.g. sample.Target, and press the '''Start Battle''' button to let the games begin!

== What's next? ==

== What's next? ==

Revision as of 23:17, 29 November 2007

This is the classic My First Robot Tutorial that tells how to create your first robot.

Creating a Robot

Creating a robot can be easy. Making your robot a winner is not. You can spend only a few minutes on it, or you can spend months and months. I'll warn you that writing a robot can be addictive! Once you get going, you'll watch your creation as it goes through growing pains, making mistakes and missing critical shots. But as you learn, you'll be able to teach your robot how to act and what to do, where to go, who to avoid, and where to fire. Should it hide in a corner, or jump into the fray?

The robot will continue doing this over and over and over, until it dies, due to the while(true) statement.

Not so bad, right?

Fire at Will!

When our radar scans a robot, we want to fire:

public void onScannedRobot(ScannedRobotEvent e) {
fire(1);
}

The game calls your onScannedRobot method whenever you can see another robot.
It sends along an event that can tell us lots of information about the robot -- its name, how much life it has, where it is, where it's heading, how fast it's going, etc.

However, since this is a simple robot, we're not going to look at any of that stuff. Let's just fire!

Compile your robot

First, save your robot by selecting the Save in the File menu. Follow the prompts to save your robot.

Now, compile it by selecting Compile in the Compiler menu.

If your robot compiles without any errors, you can start a new battle with your robot. Start a new battle by selecting New in the Battle menu. If you cannot see your robot, you might have to refresh the list of robots by pressing F5. Add your robot to the battle together with at least one other robot as e.g. sample.Target, and press the Start Battle button to let the games begin!

What's next?

You should have a look at all the sample robots to see how certain things are done.

You'll eventually want to look at the Robocode API to see all the other things your robot can do.