Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import robocode.HitRobotEvent;
- import robocode.Robot;
- import robocode.ScannedRobotEvent;
- import java.awt.*;
- public class Conor extends Robot {
- double moveAmount; // How much to move
- public void run() {
- // Set colors
- setBodyColor(Color.green);
- setGunColor(Color.white);
- setRadarColor(Color.white);
- setBulletColor(Color.green);
- setScanColor(Color.green);
- // Initialize moveAmount to the maximum possible for this battlefield.
- moveAmount = Math.max(getBattleFieldWidth(), getBattleFieldHeight());
- turnLeft(getHeading() % 90);
- ahead(moveAmount);
- turnGunRight(90);
- turnRight(90);
- while (true) {
- if (getRandomBoolean()) {
- goRight();
- }
- else goLeft();
- }
- }
- public void goRight() {
- turnGunRight(360);
- ahead(moveAmount/4);
- }
- public void goLeft() {
- turnGunRight(360);
- back(moveAmount/4);
- }
- public boolean getRandomBoolean() {
- return Math.random() < 0.5;
- }
- public void onHitRobot(HitRobotEvent e) {
- turnRight(90);
- back(moveAmount);
- }
- public void onScannedRobot(ScannedRobotEvent e) {
- fire(3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement