robocode 创建机器人

现在在robocode中创建第一个自己的坦克

         1.选择【Robot】->【Source Editor】打开机器人编辑器。

        2.选择【File】 ->【New】创建机器人,输入机器人名字,包名,便会创建一个新的机器人,系统已经给出了一段初始代码,能够进行最简单的机器人行动操作

                         

package MyRobot;
import robocode.*;
//import java.awt.Color;此行控制机器人、武器、雷达颜色

// API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html

/**
 * Wangkai - a robot by (your name here)
 */
public class Wangkai extends Robot
{
	/**
	 * run: Wangkai's default behavior
	 * run方法,控制机器人机动
	 */
	public void run() {
		// Initialization of the robot should be put here

		// After trying out your robot, try uncommenting the import at the top,
		// and the next line:

		// setColors(Color.red,Color.blue,Color.green); // body,gun,radar

		// Robot main loop
		while(true) {
			// Replace the next 4 lines with any behavior you would like
			ahead(100);//前进100像素
			turnGunRight(360);//转动武器360度
			back(100);//后退100像素
			turnGunRight(360);
		}
	}

	/**
	 * onScannedRobot: What to do when you see another robot
	 * 事件触发方法,当雷达扫到敌人时所进行的操作
	 */
	public void onScannedRobot(ScannedRobotEvent e) {
		// Replace the next line with any behavior you would like
		fire(1);//发射炮弹,能量为1
	}

	/**
	 * onHitByBullet: What to do when you're hit by a bullet
	 * 事件触发方法,当被别人击中时的操作
	 */
	public void onHitByBullet(HitByBulletEvent e) {
		// Replace the next line with any behavior you would like
		back(10);
	}
	
	/**
	 * onHitWall: What to do when you hit a wall
	 * 撞墙时的操作
	 */
	public void onHitWall(HitWallEvent e) {
		// Replace the next line with any behavior you would like
		back(20);
	}	
}
       3.选择【Compller】->【Compile】机器人便添加到了可选择列表中

       4.选择【Battle】->【New】选择自己的机器人进入战斗。







                                附:robocode的API,内含所有机器人的方法,可随时查询

                                                          点击打开链接

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值