Hi,
I am trying to make a simulation in which every time my Bee object touches a circle object a random fact about bees from an array is displayed, and it stays there until the bee touches another one of the circle objects, maybe even a different one. My code is below. The current problem I have is that the facts are being displayed and switched at a very fast rate. Below the code for the Bee class is attached.
public class DroneBee extends Actor
{
private String[] facts =
{"All drone bees are male!","Honey bee can fly 15mph!", "Honey Bee measure about 15 mm long!", "Honey bees communicate with each other by dancing!", "ALl worker bees are female!", "If a bee stings you, they die!", "Bees have five eyes!", "Bees have 2 pairs of wings!", "Bees live about 4 weeks!", "Bees have two stomachs!"};
public DroneBee()
{
}
public void act()
{
int i = 0;
for(int k = 0; i < Greenfoot.getRandomNumber(10); k++)
{
i++;
}
keyControls();
if(isTouching(Circle.class))
{
getWorld().showText(""+facts[i],200,200);
}
else
{
getWorld().showText("", 200,200);
}
}
public void keyControls()
{
if (Greenfoot.isKeyDown("up"))
{
setRotation(270);
setLocation(getX(), getY()-2);
}
if (Greenfoot.isKeyDown("down"))
{
setRotation(90);
setLocation(getX(), getY()+2);
}
if (Greenfoot.isKeyDown("left"))
{
setRotation(180);
setLocation(getX()-2, getY());
}
if (Greenfoot.isKeyDown("right"))
{
setRotation(0);
setLocation(getX()+2, getY());
}
}
}
