1 /** 2 * Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://robocode.sourceforge.net/license/epl-v10.html 7 */ 8 package sample; 9 10 11 import robocode.AdvancedRobot; 12 import robocode.HitRobotEvent; 13 import robocode.ScannedRobotEvent; 14 15 import java.awt.*; 16 17 18 /** 19 * SpinBot - a sample robot by Mathew Nelson. 20 * <p/> 21 * Moves in a circle, firing hard when an enemy is detected. 22 * 23 * @author Mathew A. Nelson (original) 24 * @author Flemming N. Larsen (contributor) 25 */ 26 public class SpinBot extends AdvancedRobot { 27 28 /** 29 * SpinBot's run method - Circle 30 */ run()31 public void run() { 32 // Set colors 33 setBodyColor(Color.blue); 34 setGunColor(Color.blue); 35 setRadarColor(Color.black); 36 setScanColor(Color.yellow); 37 38 // Loop forever 39 while (true) { 40 // Tell the game that when we take move, 41 // we'll also want to turn right... a lot. 42 setTurnRight(10000); 43 // Limit our speed to 5 44 setMaxVelocity(5); 45 // Start moving (and turning) 46 ahead(10000); 47 // Repeat. 48 } 49 } 50 51 /** 52 * onScannedRobot: Fire hard! 53 */ onScannedRobot(ScannedRobotEvent e)54 public void onScannedRobot(ScannedRobotEvent e) { 55 fire(3); 56 } 57 58 /** 59 * onHitRobot: If it's our fault, we'll stop turning and moving, 60 * so we need to turn again to keep spinning. 61 */ onHitRobot(HitRobotEvent e)62 public void onHitRobot(HitRobotEvent e) { 63 if (e.getBearing() > -10 && e.getBearing() < 10) { 64 fire(3); 65 } 66 if (e.isMyFault()) { 67 turnRight(10); 68 } 69 } 70 } 71