there are ob1s are location in different places randomly. and robot1 is also palce in randomly..what i want to know is how can my robot identify the nearest path and go to the nearst object and grab it first and go to the next nearest object and finally go to the end location.
here is my robot class
here is my object class
and here is my world class
public class Robot1 extends Actor
{
/**
* Act - do whatever the Robot1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (getWorld().getObjects(ob1.class).isEmpty())
{
chaseEnd();
}
else
{
chaseOb1();
}
// Add your action code here.
}
public void chaseOb1(){
turnTowards(ob1.objX1, ob1.objY1);
Actor ob1=getOneIntersectingObject(ob1.class);
getWorld().removeObject(ob1);
move(2);
}
public void chaseEnd(){
turnTowards(end1.endX2, end1.endY2);
Actor end1=getOneIntersectingObject(end1.class);
getWorld().removeObject(end1);
move(2);
}
}
public class ob1 extends Actor
{
/**
* Act - do whatever the ob1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public static int objX1, objY1;
public void act()
{
objX1=getX();
objY1=getY();
// Add your action code here.
}
}
public class MyWorld extends World
{
public void act(){
if (getObjects(end.class).isEmpty() && getObjects(end1.class).isEmpty()) Greenfoot.stop();
}
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1150, 600, 1);
prepaire();
}
public void prepaire(){
Robot1 a1 = new Robot1();
int aX1=Greenfoot.getRandomNumber(getWidth());
int aY1=Greenfoot.getRandomNumber(getHeight());
addObject(a1,aX1,aY1);
}}

