Question: Grid World project Run Error !! help please!!

Ads

 
 
 

Share on Google+Share on Google+

Seungkwon Lee
Grid World project Run Error !! help please!!
1 Answer(s)      6 years and 2 months 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 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!!

Ads
View Answers

March 18, 2011 at 8:12 AM


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


Ads









Related Tutorials/Questions & Answers:
Tutorials   
Java Spring Hibernate Struts Training code for programming How can I dynamically load user-entered data as content of jquery dialog? java webcam integration question java coding Fix Scrollbar position in a checkboxList after postback Information Save Alert Country wise redirection to files Interface in javascript connect database with javascript Zip Code ZipCode how to validate the email login How to play FLV video files on Ipad using HTML code or javascript code? Nitobi Grid is not working in IE10/IE11 jquery issue plese help RegEx Tree structure from json whose parents can be dragged and dropped from child newyorklife insurance getElementById not working javascript code for search in html file Implement The Skeleton Code Implement This Skeleton Code Mobile Automation using Appium Computer forensic application Java: Searching a string from doc files java linked list urgent !!! java linked list urgent!!! library management library management library management library management question Html form using JavaScript to display the table content java how to prevent no from unroundin off on clicking text box again in JSP and Jquery graph generation from xml design file display data from database in textbox when id entered in textbox Javascript Code for all fields how to get HTTP GET request value using javascript array Javascript Querry autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me Create SpreadSheet same as excel using java applet Create SpreadSheet same as excel using java applet How to change focus among multiple select boxes? Write JQUERY Code Write JQUERY Code Converting jsp variable to java variable java

Ads

 
Advertisement null

Ads