package sakabe;
import robocode.*;
import java.awt.Color;
public class Bebe00 extends Robot
{
public void run() {
setColors(Color.red,Color.blue,Color.green);
while(true) {
// ロボットの方向を取得
double rh = getHeading();
// 真上か真下以外の時に方向転換
if(rh % 180 != 0){
if(rh <=90) turnLeft(rh);
if(rh >= 270) turnRight(360 - rh);
if(rh > 90 && rh <= 180) turnRight(180 - rh);
if(rh > 180 && rh < 270) turnLeft(rh - 180);
}
ahead(200);
turnGunRight(360);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
// 敵までの距離が200ピクセルの時のみ最大レベルで攻撃
if(e.getDistance() <= 200){
fire(3);
}
}
public void onHitByBullet(HitByBulletEvent e) {
turnLeft(90 - e.getBearing());
}
public void onHitWall(HitWallEvent e){
turnLeft(180);
ahead(200);
}
}
[オブジェクト指向プログラミング(H16)]