2017-08-02 42 views
-1

我确定我可以自己弄明白这一点,但我觉得我写的方式已经太昂贵了。我有一个碰撞函数,在第三if语句中,它检查入侵者(宽度为11的矩形)是否与监视摄像机(弧)发生碰撞,如果if那么发生那么我想激活我的功能,安全机器人追逐入侵者。如何在退出循环后激活一个循环内的函数

< - 重要提示:checkShapeIntersection功能是时间轴事件,因此它的运行中不断 - >

private boolean checkShapeIntersection(Shape block) { 
    //Name to check for intruder and surveillance collision 
    String Surveillance = "Arc"; 

    boolean collisionDetected = false; 
    for (Shape static_bloc : nodes) { 
     if (static_bloc != block) { 
      Shape intersect = Shape.intersect(block, static_bloc); 
      if (intersect.getBoundsInLocal().getWidth() != -1) { 
       collisionDetected = true; 
       //Checks of intruder collides with an arc (surveillance), the 11th width is only for intruder rectangles 
       if (Surveillance.equals(block.getClass().getSimpleName()) && static_bloc.getBoundsInLocal().getWidth() == 11) { 
        //Activate Chase function 
        testRobot.chaseIntruder(static_bloc); 
        detected = true; 
       } 
      } 
     } 
    } 

    if (collisionDetected) { 
     block.setFill(Color.BLUE); 
    } else { 
     block.setFill(Color.RED); 
    } 

    return detected; 
} 

我的警卫机器人内部

public void chaseIntruder(Shape intruder) { 
    destinationsList.add(new Vector2D(intruder.getLayoutBounds().getMinX(),intruder.getLayoutBounds().getMinY())); 
    this.updatePosition(); 
} 
+0

循环后继续意味着什么?你不用循环创建新的线程。因此该方法被调用一次,并且在完成后,在您调用该方法的行之后继续进行评估。 – Milkmaid

+0

以目前的方式,我的安全机器人只会在最后一条if语句满足的情况下向入侵者移动,一旦入侵者离开机器人,机器人就会停止向入侵者移动,但是我希望机器人继续追逐入侵者直到他抓住他。 – bigPoppa350

回答