Show your revised Magic8Ball class codes.
import greenfoot.*;
public class Magic8Ball extends SmoothMover
{
//Leave this field alone, this will be the Triangle on the screen
private TriangleAnswer triangle = new TriangleAnswer();
public void act()
{
// Ask if the mouse has been dragged on the current object
// If so, build a MouseInfo variable and get the mouse from Greenfoot
// Teleport to the location of the Mouse
// Ask if you are touching a TriangleAnswer
// If so, remove the TriangleAnswer
MouseInfo m = Greenfoot.getMouseInfo();
int mx = m.getX();
int my = m.getY();
if (m != null && m.getActor() == this)
{
setLocation(mx, my);
if(isTouching(TriangleAnswer.class))
{
getWorld().removeObject(triangle);
}
}
// Ask if the mouse has stopped being dragged on the current object
// If so, call triangle's randomize method
// Create two variables, xMove and yMove, set them to
// a random value from {-100, -99, -98, ... 99, 100 }
// add the triangle to the world at (yourX + xMove, yourY + yMove)
if (m != null && m.getActor() != this)
{
triangle.randomize();
int xMove = (int)(Math.random()*201)-100;
int yMove = (int)(Math.random()*201)-100;
getWorld().addObject(triangle, getX() + xMove, getY() + yMove);
}
}
}
MouseInfo m = Greenfoot.getMouseInfo();
if (m != null)
{
if (m.getActor() == this)
{
setLocation(m.getX(), m.getY());
removeTouching(TriangleAnswer.class);
}
else
{
// the triangle
}
}