我以为我可以通过从轮数中减去死亡数来计算轮次赢额值,但我的计数器没有递增:
public void onRoundEnded(RoundEndedEvent event)
{
roundCount++;
}
public void onDeath(DeathEvent event)
{
deathCount++;
}
日志中没有出现任何编译错误或任何其他错误。当我将变量输出到onBattleEnded事件中的日志时,输出(在100轮之后)是:
roundCount=1
deathCount=0
以下完整代码:
public class AB extends AdvancedRobot
{
private int deathCount;
private int roundCount;
public void run()
{
while(true)
{
ahead(100);
turnGunRight(360);
back(100);
turnGunRight(360);
}
}
public void onScannedRobot(ScannedRobotEvent e)
{
fire(1);
}
public void onHitByBullet(HitByBulletEvent e)
{
back(10);
}
public void onHitWall(HitWallEvent e)
{
back(20);
}
public void onRoundEnded(RoundEndedEvent event)
{
roundCount++;
}
public void onDeath(DeathEvent event)
{
deathCount++;
}
public void onBattleEnded(BattleEndedEvent event)
{
System.out.println("roundCount=" + roundCount);
System.out.println("deathCount=" + deathCount);
}
}
使用的Robocode版本是1.9.2.6