Grid World project Run Error !! help please!!

Grid World project Run Error !! help please!!

i'm trying to make a bug multiply when it hits a rock or another bug or a side the bug will remove itself from the grid and add 2 bugs to a empty location. It "steps" but does not "run"

here is my code:

import info.gridworld.grid.Location; import info.gridworld.grid.Grid; import java.util.Random; import info.gridworld.actor.Bug; import info.gridworld.actor.Actor; import info.gridworld.actor.ActorWorld; import info.gridworld.world.World; import java.util.ArrayList; import java.lang.Object;

public class MultiplyingBug extends Bug {

 private int steps ;
 private int sideLength;



public MultiplyingBug(int length)
{
    steps = 0;
    sideLength = length;
}


/**
 * Moves to the next location of the diagnol.
 */


public void act()
{


    if (steps < sideLength && canMove())
    {
        move();
        steps++;
    }
    else
    {
        turn();
        turn();

        steps = 0;


    }


   Grid<Actor> gr = getGrid();
    if (gr == null)
    {
        return;
    }   


        //Use RandomGenerator to determine where to put the bug on the grid
    Random randomGenerator = new Random();
    for ( int idx = 0; idx <= 9; idx++)
    {


        randomGenerator.nextInt();
        randomGenerator.nextInt();


        //when a bug cannot move , creates a new bug in new location
     if (canMove() == false)
    {



        Location old = getLocation();
        removeSelfFromGrid();
        MultiplyingBug NewBug= new MultiplyingBug(100); 
        Location another = new Location (randomGenerator.nextInt(10), randomGenerator.nextInt(10));
        NewBug.putSelfInGrid(gr, another);

         MultiplyingBug NewBug2= new MultiplyingBug(100); 
        Location another2 = new Location (randomGenerator.nextInt(10), randomGenerator.nextInt(10));
        NewBug2.putSelfInGrid(gr, another2);

  }      
}

} }

and Here is my error...:
(it runs at first but when the bug hits a side, the error occurs and i exit the error but run does not work anymore)

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: This actor is not contained in a grid. at info.gridworld.actor.Actor.removeSelfFromGrid(Actor.java:136) at MultiplyingBug.act(MultiplyingBug.java:90) at info.gridworld.actor.ActorWorld.step(ActorWorld.java:68) at info.gridworld.gui.GUIController.step(GUIController.java:134) at info.gridworld.gui.GUIController$2.actionPerformed(GUIController.java:109) at javax.swing.Timer.fireActionPerformed(Timer.java:271) at javax.swing.Timer$DoPostEvent.run(Timer.java:201) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEvent(EventQueue.java:597) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

thank you...PLEASE HELP ME!!

View Answers

March 18, 2011 at 8:12 AM

ignore the comment " move to the next location of diagonal...









Related Tutorials/Questions & Answers:

Ads