I have 5 Objects food and 100 ants and i have to examine the accordence of the location of an ant and a food. The food has a permanent location, the ants are moving randomly. I implimented the ants and the food in the Worldclass and want to examine the location of the food with an ant.
Here I implimented the food and ants:
public class Waldboden extends World
{
/**
* Constructor for objects of class Waldboden.
*
*/
public Forest()
{
super(500, 500, 1);
int a = new int ;
for (int i = 0; i<100; i++){
Ant ant = new Ant();
addObject(ant, 250, 250);
addObject(ant, 250, 250);
}
}
for (int k = 0; k<5;k++){
Food food = new Food;
double x = Math.random()*500;
double y = Math.random()*500;
addObject(food, (int)x, (int)y);
//addObject(food, (int)x, (int)y);
}
}
}
Here I am examining the locations:
public class Ameise extends Actor
{
public void act ()
{
this.turn();
this.move();
int aktuellesX = this.getX();
int aktuellesY = this.getY();
for (int k =0;k<5;k++){
if (this.getX() == food.x && this.getY == food.y){
if (food.x<250){
int xSteps=250/food.x;
int merker=250%food.x;
}else{
xSteps=food.x/250;
merker=food.x%250;
}
But it won't compile, because Greenfoot reports "cannot find simbol- variable food" what do i have to change?
