Seungkwon Lee
Grid World project Run Error !! help please!!
1 Answer(s)      6 years ago
Posted in : JavaScript Questions

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; import; import; import; 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())

        steps = 0;


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

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


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

        Location old = getLocation();
        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 at MultiplyingBug.act( at at info.gridworld.gui.GUIController.step( at info.gridworld.gui.GUIController$2.actionPerformed( at javax.swing.Timer.fireActionPerformed( at javax.swing.Timer$ at java.awt.event.InvocationEvent.dispatch( at java.awt.EventQueue.dispatchEvent( at java.awt.EventDispatchThread.pumpOneEventForFilters( at java.awt.EventDispatchThread.pumpEventsForFilter( at java.awt.EventDispatchThread.pumpEventsForHierarchy( at java.awt.EventDispatchThread.pumpEvents( at java.awt.EventDispatchThread.pumpEvents( at

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: