package squidM; import robocode.*; import java.awt.*; import robocode.util.Utils; // API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html /** * Squidman 2.4 - a robot by (Blubex)-- LATEST VERSION */ public class Squidman extends AdvancedRobot { /** * run: Squidman's yodeling fun time */ double previousEnergy = 100; int dir = 1; // ----------------- public void run() { setAdjustRadarForGunTurn(true); setAdjustRadarForRobotTurn(true); setAdjustGunForRobotTurn(true); setColors(Color.red,Color.pink,Color.red,Color.red,Color.pink); // body,gun,radar,bullets,scan arc setTurnRadarRight(Double.POSITIVE_INFINITY); // Radar Lock } public void onScannedRobot(ScannedRobotEvent e) { // Stay at right angles to the opponent setTurnRight(e.getBearing()+90- 30*dir); double changeInEnergy = previousEnergy-e.getEnergy(); if (changeInEnergy>0 && changeInEnergy<=3) { // run away dir = -dir; setAhead((e.getDistance()/4+25)); } //radar lock cont. setTurnRadarLeft(getRadarTurnRemaining()); //linear target double power = 2; double bVel = 20 - (power * 3); double absoluteBearing = getHeadingRadians() + e.getBearingRadians(); setTurnGunRightRadians(Utils.normalRelativeAngle (absoluteBearing - getGunHeadingRadians() + (e.getVelocity() * Math.sin(e.getHeadingRadians() - absoluteBearing) / bVel))); fire(power); // Track the energy level previousEnergy = e.getEnergy(); } public void onHitWall(HitWallEvent e) { double move; move = e.getBearing(); if (move > 0) { setTurnLeft(180); } else { setTurnRight(180); } ahead(200); } public void onBulletHit(BulletHitEvent event) { setColors(Color.orange,Color.red,Color.black,Color.red,Color.pink); } public void onBulletMissed(BulletMissedEvent event) { setColors(Color.red,Color.pink,Color.red,Color.red,Color.pink); } public void onWin (WinEvent e) { //WIN WIN WIN WIN WIN setColors(Color.orange,Color.red,Color.black,Color.red,Color.orange); setTurnLeft(360); ahead(30); back(30); setTurnRight(360); } //end }
- 粉丝: 0
- 资源: 4
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助