我正在Robocode中創建一個簡單的機器人。我有一個函數牆壁如下圖所示:未在Robocode中調用onScannedRobot方法
public void walls() {
see = false;
wallBool = true;
double maxMove = Math.max(getBattleFieldWidth(), getBattleFieldHeight());
turnLeft(getHeading() % 90);
ahead(maxMove);
see = true;
turnRight(90);
turnGunRight((getHeading() - getGunHeading())+ 90);
while (getEnergy() <= 115) {
wallBool = true;
see = true;
ahead(maxMove);
see = false;
turnRight(90);
}
}
注意see
和wallBool
是已經被前面我的代碼中聲明的變量。在函數內的while循環中,我調用turnRight();
方法,該方法應自動掃描其他機器人。然而,我的代碼在我onScannedRobot
功能不運行,下面包括:
public void onScannedRobot(ScannedRobotEvent e) {
System.out.println("check");
if (see==true) {
System.out.println("check2");
scan();
}
if (wallBool==true) {
fire(2);
}
檢查永遠不會打印到控制檯。怎麼了?
任何幫助將不勝感激......
我會建議簡化您的代碼,只需旋轉雷達和打印,如果你得到一個掃描事件。然後建立起你在這裏所擁有的東西。 – NonlinearFruit
另外,如果您嘗試在掃描的機器人上拍攝,使用'ScannedRobotEvent'放置您的鏡頭。示例機器人的源代碼是一個很好的開始。 – NonlinearFruit