robocode 创建机器人
生活随笔
收集整理的這篇文章主要介紹了
robocode 创建机器人
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
現(xiàn)在在robocode中創(chuàng)建第一個自己的坦克
???????? 1.選擇【Robot】->【Source Editor】打開機器人編輯器。
??????? 2.選擇【File】 ->【New】創(chuàng)建機器人,輸入機器人名字,包名,便會創(chuàng)建一個新的機器人,系統(tǒng)已經(jīng)給出了一段初始代碼,能夠進行最簡單的機器人行動操作
?????????????????????????
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 loopwhile(true) {// Replace the next 4 lines with any behavior you would likeahead(100);//前進100像素turnGunRight(360);//轉(zhuǎn)動武器360度back(100);//后退100像素turnGunRight(360);}}/*** onScannedRobot: What to do when you see another robot* 事件觸發(fā)方法,當(dāng)雷達掃到敵人時所進行的操作*/public void onScannedRobot(ScannedRobotEvent e) {// Replace the next line with any behavior you would likefire(1);//發(fā)射炮彈,能量為1}/*** onHitByBullet: What to do when you're hit by a bullet* 事件觸發(fā)方法,當(dāng)被別人擊中時的操作*/public void onHitByBullet(HitByBulletEvent e) {// Replace the next line with any behavior you would likeback(10);}/*** onHitWall: What to do when you hit a wall* 撞墻時的操作*/public void onHitWall(HitWallEvent e) {// Replace the next line with any behavior you would likeback(20);} }?????? 3.選擇【Compller】->【Compile】機器人便添加到了可選擇列表中?????? 4.選擇【Battle】->【New】選擇自己的機器人進入戰(zhàn)斗。
??????????????????????????????? 附:robocode的API,內(nèi)含所有機器人的方法,可隨時查詢
????????????????????????????????????????????????????????? 點擊打開鏈接
總結(jié)
以上是生活随笔為你收集整理的robocode 创建机器人的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bucket sort sample s
- 下一篇: 路由懒加载优化