I am developing a scenario with two robots movements.i want to wait one robot until other robot finish it's opertion. how can i wait it.. my code is here
public class MyWorld extends World
{
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
prepare();
}
private void prepare(){
man1 man1=new man1();
int manX1=Greenfoot.getRandomNumber(getWidth());
int manY2=Greenfoot.getRandomNumber(getHeight());
addObject(man1, manX1, manY2);
man2 man2=new man2();
int manX12=Greenfoot.getRandomNumber(getWidth());
int manY21=Greenfoot.getRandomNumber(getHeight());
addObject(man2, manX12, manY21);
Barrel[] barel=new Barrel[1];
for(int i=0;i<barel.length;i++){
barel[i]=new Barrel();
int manX=Greenfoot.getRandomNumber(getWidth());
int manY=Greenfoot.getRandomNumber(getHeight());
addObject(barel[i],manX,manY);
}
}}
public class man1 extends Actor
{
/**
* Act - do whatever the man1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveAround(); // Add your action code here.
}
public void moveAround(){
move(4);
if(Greenfoot.getRandomNumber(100)<10){
turn(Greenfoot.getRandomNumber(180)-90);
}
}
}
public class man2 extends Actor
{
/**
* Act - do whatever the man2 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveAround(); // Add your action code here.
}
public void moveAround(){
move(2);
if(Greenfoot.getRandomNumber(100)<10){
turn(Greenfoot.getRandomNumber(180)-90);
}
}
}

